-
Notifications
You must be signed in to change notification settings - Fork 116
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FIX Ensure files can be removed from elemental blocks #1267
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -656,15 +656,9 @@ public function getRenderTemplates($suffix = '') | |
*/ | ||
public function updateFromFormData($data) | ||
{ | ||
$cmsFields = $this->getCMSFields(); | ||
|
||
foreach ($data as $field => $datum) { | ||
$field = $cmsFields->dataFieldByName($field); | ||
|
||
if (!$field) { | ||
continue; | ||
} | ||
|
||
$cmsFields = $this->getCMSFields()->saveableFields(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Getting the |
||
foreach ($cmsFields as $fieldName => $field) { | ||
$datum = $data[$fieldName] ?? null; | ||
Comment on lines
+660
to
+661
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If there's data, set to the value in the data - otherwise set to null. This is still skipping a bunch of stuff that |
||
$field->setSubmittedValue($datum); | ||
$field->saveInto($this); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
@retry @job2 | ||
Feature: Files can be saved in and removed from elemental blocks | ||
As a CMS user | ||
I want to attach and remove files from elemental blocks | ||
|
||
Background: | ||
Given I add an extension "DNADesign\Elemental\Extensions\ElementalPageExtension" to the "Page" class | ||
And I add an extension "SilverStripe\FrameworkTest\Elemental\Extension\FileElementalExtension" to the "DNADesign\Elemental\Models\ElementContent" class | ||
And I go to "/dev/build?flush" | ||
And a "image" "file1.jpg" | ||
And a "page" "Blocks Page" with a "My title" content element with "My content" content | ||
And the "group" "EDITOR" has permissions "Access to 'Pages' section" | ||
And I am logged in as a member of "EDITOR" group | ||
And I go to "/admin/pages" | ||
And I follow "Blocks Page" | ||
|
||
Scenario: Add a file and save the block, then remove the file and save the block | ||
# Add a file to the block | ||
Given I click on the caret button for block 1 | ||
Then I should not see "file1" | ||
Given I take a screenshot after every step | ||
When I click "Choose existing" in the "#Form_ElementForm_1 .uploadfield" element | ||
And I press the "Back" HTML field button | ||
And I click on the file named "file1" in the gallery | ||
And I press the "Insert" button | ||
And I press the "View actions" button | ||
And I click on the ".element-editor__actions-save" element | ||
Then I should see a "Saved 'My title' successfully" success toast | ||
# Check we see the file both in the current page load (react state is correct) and after reloading the form | ||
Then I should see "file1" | ||
When I go to "/admin/pages" | ||
And I follow "Blocks Page" | ||
And I click on the caret button for block 1 | ||
Then I should see "file1" | ||
# Then remove the file from the block | ||
And I click on the "#Form_ElementForm_1 .uploadfield-item__remove-btn" element | ||
And I press the "View actions" button | ||
And I click on the ".element-editor__actions-save" element | ||
Then I should see a "Saved 'My title' successfully" success toast | ||
# Check we don't see the file anymore | ||
Then I should not see "file1" | ||
When I go to "/admin/pages" | ||
And I follow "Blocks Page" | ||
And I click on the caret button for block 1 | ||
Then I should not see "file1" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really we should just rename the fields in the form, and then call
$form->saveInto($element)
- but doing that now would be an API break because someone may have customised theupdateFromFormData()
method in their custom elements.