silverstripe / silverstripe-elemental

Create pages in Silverstripe CMS using content blocks
http://dna.co.nz
BSD 3-Clause "New" or "Revised" License
110 stars 115 forks source link

Saving a block inline then saving the page fails with 500 error #722

Open robbieaverill opened 5 years ago

robbieaverill commented 5 years ago

CWP 2.4.x-dev

See the server error response:

[Emergency] Uncaught TypeError: Argument 1 passed to DNADesign\Elemental\Controllers\ElementalAreaController::removeNamespacesFromFields() must be of the type array, null given, called in /Users/robbieaverill/dev/cwp24/vendor/dnadesign/silverstripe-elemental/src/Forms/ElementalAreaField.php on line 246
POST /admin/pages/edit/EditForm/12/
Line 204 in /Users/robbieaverill/dev/cwp24/vendor/dnadesign/silverstripe-elemental/src/Controllers/ElementalAreaController.php

Source
195     }
196 
197     /**
198      * Remove the pseudo namespaces that were added to form fields by the form factory
199      *
200      * @param array $data
201      * @param int $elementID
202      * @return array
203      */
204     public static function removeNamespacesFromFields(array $data, $elementID)
205     {
206         $output = [];
207         $template = sprintf(EditFormFactory::FIELD_NAMESPACE_TEMPLATE, $elementID, '');
208         foreach ($data as $key => $value) {
209             // Only look at fields that match the namespace template
210             if (substr($key, 0, strlen($template)) !== $template) {
Trace
DNADesign\Elemental\Controllers\ElementalAreaController::removeNamespacesFromFields(, 5) 
ElementalAreaField.php:246
DNADesign\Elemental\Forms\ElementalAreaField->saveInto(BlocksPage) 
Form.php:1532
SilverStripe\Forms\Form->saveInto(BlocksPage) 
CMSMain.php:1799

Workaround: refresh the page, then saving works again, or save the blocks inline if you have unsaved changes. I suspect this bug will only come up if you haven't opened any blocks for inline editing though.

christopherdarling commented 4 years ago

A client experienced this today, not on a CWP project. Thank you for sharing the workaround @robbieaverill.