Skip to content

Commit 5f8f754

Browse files
committed
Merge branch '5.3' into 5
# Conflicts: # src/Models/BaseElement.php
2 parents 50ca5a8 + 23af9c0 commit 5f8f754

File tree

3 files changed

+51
-10
lines changed

3 files changed

+51
-10
lines changed

src/Controllers/ElementalAreaController.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,9 @@ public function save(array $data, Form $form): HTTPResponse
138138
// Remove the namespace prefixes that were added by EditFormFactory
139139
$dataWithoutNamespaces = static::removeNamespacesFromFields($data, $element->ID);
140140

141-
// Update and write the data object which will trigger model validation
141+
// Update and write the data object which will trigger model validation.
142+
// Would usually be handled by $form->saveInto($element) but since the field names
143+
// in the form have been namespaced, we need to handle it ourselves.
142144
$element->updateFromFormData($dataWithoutNamespaces);
143145
if ($element->isChanged()) {
144146
try {

src/Models/BaseElement.php

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -658,15 +658,9 @@ public function getRenderTemplates($suffix = '')
658658
public function updateFromFormData($data)
659659
{
660660
Deprecation::noticeWithNoReplacment('5.4.0');
661-
$cmsFields = $this->getCMSFields();
662-
663-
foreach ($data as $field => $datum) {
664-
$field = $cmsFields->dataFieldByName($field);
665-
666-
if (!$field) {
667-
continue;
668-
}
669-
661+
$cmsFields = $this->getCMSFields()->saveableFields();
662+
foreach ($cmsFields as $fieldName => $field) {
663+
$datum = $data[$fieldName] ?? null;
670664
$field->setSubmittedValue($datum);
671665
$field->saveInto($this);
672666
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
@retry @job2
2+
Feature: Files can be saved in and removed from elemental blocks
3+
As a CMS user
4+
I want to attach and remove files from elemental blocks
5+
6+
Background:
7+
Given I add an extension "DNADesign\Elemental\Extensions\ElementalPageExtension" to the "Page" class
8+
And I add an extension "SilverStripe\FrameworkTest\Elemental\Extension\FileElementalExtension" to the "DNADesign\Elemental\Models\ElementContent" class
9+
And I go to "/dev/build?flush"
10+
And a "image" "file1.jpg"
11+
And a "page" "Blocks Page" with a "My title" content element with "My content" content
12+
And the "group" "EDITOR" has permissions "Access to 'Pages' section"
13+
And I am logged in as a member of "EDITOR" group
14+
And I go to "/admin/pages"
15+
And I follow "Blocks Page"
16+
17+
Scenario: Add a file and save the block, then remove the file and save the block
18+
# Add a file to the block
19+
Given I click on the caret button for block 1
20+
Then I should not see "file1"
21+
Given I take a screenshot after every step
22+
When I click "Choose existing" in the "#Form_ElementForm_1 .uploadfield" element
23+
And I press the "Back" HTML field button
24+
And I click on the file named "file1" in the gallery
25+
And I press the "Insert" button
26+
And I press the "View actions" button
27+
And I click on the ".element-editor__actions-save" element
28+
Then I should see a "Saved 'My title' successfully" success toast
29+
# Check we see the file both in the current page load (react state is correct) and after reloading the form
30+
Then I should see "file1"
31+
When I go to "/admin/pages"
32+
And I follow "Blocks Page"
33+
And I click on the caret button for block 1
34+
Then I should see "file1"
35+
# Then remove the file from the block
36+
And I click on the "#Form_ElementForm_1 .uploadfield-item__remove-btn" element
37+
And I press the "View actions" button
38+
And I click on the ".element-editor__actions-save" element
39+
Then I should see a "Saved 'My title' successfully" success toast
40+
# Check we don't see the file anymore
41+
Then I should not see "file1"
42+
When I go to "/admin/pages"
43+
And I follow "Blocks Page"
44+
And I click on the caret button for block 1
45+
Then I should not see "file1"

0 commit comments

Comments
 (0)