Skip to content

Commit

Permalink
FIX Ensure files can be removed from elemental blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
GuySartorelli committed Nov 5, 2024
1 parent 13f6a3f commit 94cd28b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
4 changes: 3 additions & 1 deletion src/Controllers/ElementalAreaController.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,9 @@ public function save(array $data, Form $form): HTTPResponse
// Remove the namespace prefixes that were added by EditFormFactory
$dataWithoutNamespaces = static::removeNamespacesFromFields($data, $element->ID);

// Update and write the data object which will trigger model validation
// Update and write the data object which will trigger model validation.
// Would usually be handled by $form->saveInto($element) but since the field names
// in the form have been namespaced, we need to handle it ourselves.
$element->updateFromFormData($dataWithoutNamespaces);
if ($element->isChanged()) {
try {
Expand Down
12 changes: 3 additions & 9 deletions src/Models/BaseElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
foreach ($cmsFields as $fieldName => $field) {
$datum = $data[$fieldName] ?? null;
$field->setSubmittedValue($datum);
$field->saveInto($this);
}
Expand Down

0 comments on commit 94cd28b

Please sign in to comment.