verbb / vizy

A flexible visual editor for Craft CMS
Other
44 stars 8 forks source link

Error thrown after renaming a matrix field and editing an entry #99

Closed alexroper closed 2 years ago

alexroper commented 2 years ago

Description

I renamed a field in a matrix used in a Vizy block. When trying to edit an entry with existing matrix data (i.e. using the old field name), I get a "Setting unknown property" exception thrown.

In my case I have a matrix field called "Typologies List" with a block type "Typology" and a field "Related Typology" that was renamed to just "Typology."

Might be related to issue #49.

Unknown Property – [yii\base\UnknownPropertyException](http://www.yiiframework.com/doc-2.0/yii-base-unknownpropertyexception.html)
Setting unknown property: craft\behaviors\CustomFieldBehavior::relatedTypology

yii\base\UnknownPropertyException: Setting unknown property: craft\behaviors\CustomFieldBehavior::relatedTypology in /app/vendor/yiisoft/yii2/base/BaseObject.php:163
Stack trace:
#0 /app/storage/runtime/compiled_classes/CustomFieldBehavior_2@pyphaxcrgq.php(445): yii\base\BaseObject->__set('relatedTypology', Array)
#1 /app/vendor/craftcms/cms/src/base/Element.php(3348): craft\behaviors\CustomFieldBehavior->__set('relatedTypology', Array)
#2 /app/vendor/craftcms/cms/src/base/Element.php(3327): craft\base\Element->setFieldValue('relatedTypology', Array)
#3 /app/vendor/craftcms/cms/src/fields/Matrix.php(1308): craft\base\Element->setFieldValues(Array)
#4 /app/vendor/craftcms/cms/src/fields/Matrix.php(520): craft\fields\Matrix->_createBlocksFromSerializedData(Array, Object(verbb\vizy\elements\Block))
#5 /app/vendor/craftcms/cms/src/base/Element.php(4278): craft\fields\Matrix->normalizeValue(Array, Object(verbb\vizy\elements\Block))
#6 /app/vendor/craftcms/cms/src/base/Element.php(3337): craft\base\Element->normalizeFieldValue('typologiesList')
#7 /app/vendor/craftcms/cms/src/fieldlayoutelements/CustomField.php(233): craft\base\Element->getFieldValue('typologiesList')
#8 /app/vendor/craftcms/cms/src/fieldlayoutelements/BaseField.php(203): craft\fieldlayoutelements\CustomField->inputHtml(Object(verbb\vizy\elements\Block), false)
#9 /app/vendor/craftcms/cms/src/fieldlayoutelements/CustomField.php(213): craft\fieldlayoutelements\BaseField->formHtml(Object(verbb\vizy\elements\Block), false)
#10 /app/vendor/craftcms/cms/src/web/View.php(1499): craft\fieldlayoutelements\CustomField->craft\fieldlayoutelements\{closure}()
#11 /app/vendor/craftcms/cms/src/fieldlayoutelements/CustomField.php(214): craft\web\View->namespaceInputs(Object(Closure), 'fields')
#12 /app/vendor/craftcms/cms/src/models/FieldLayout.php(594): craft\fieldlayoutelements\CustomField->formHtml(Object(verbb\vizy\elements\Block), false)
#13 /app/vendor/craftcms/cms/src/web/View.php(1494): craft\models\FieldLayout->craft\models\{closure}()
#14 /app/vendor/craftcms/cms/src/models/FieldLayout.php(593): craft\web\View->namespaceInputs(Object(Closure), NULL)
#15 /app/vendor/verbb/vizy/src/fields/VizyField.php(584): craft\models\FieldLayout->createForm(Object(verbb\vizy\elements\Block))
#16 /app/vendor/verbb/vizy/src/fields/VizyField.php(182): verbb\vizy\fields\VizyField->_getBlocksForInput(Object(verbb\vizy\models\NodeCollection), 'ohcrboxeln', Object(craft\elements\Entry))
#17 /app/vendor/craftcms/cms/src/fieldlayoutelements/CustomField.php(252): verbb\vizy\fields\VizyField->getInputHtml(Object(verbb\vizy\models\NodeCollection), Object(craft\elements\Entry))
#18 /app/vendor/craftcms/cms/src/fieldlayoutelements/BaseField.php(203): craft\fieldlayoutelements\CustomField->inputHtml(Object(craft\elements\Entry), false)
#19 /app/vendor/craftcms/cms/src/fieldlayoutelements/CustomField.php(213): craft\fieldlayoutelements\BaseField->formHtml(Object(craft\elements\Entry), false)
#20 /app/vendor/craftcms/cms/src/web/View.php(1499): craft\fieldlayoutelements\CustomField->craft\fieldlayoutelements\{closure}()
#21 /app/vendor/craftcms/cms/src/fieldlayoutelements/CustomField.php(214): craft\web\View->namespaceInputs(Object(Closure), 'fields')
#22 /app/vendor/craftcms/cms/src/models/FieldLayout.php(594): craft\fieldlayoutelements\CustomField->formHtml(Object(craft\elements\Entry), false)
#23 /app/vendor/craftcms/cms/src/web/View.php(1494): craft\models\FieldLayout->craft\models\{closure}()
#24 /app/vendor/craftcms/cms/src/models/FieldLayout.php(593): craft\web\View->namespaceInputs(Object(Closure), NULL)
#25 /app/vendor/twig/twig/src/Extension/CoreExtension.php(1564): craft\models\FieldLayout->createForm(Object(craft\elements\Entry), false, Array)
#26 /app/vendor/craftcms/cms/src/helpers/Template.php(106): twig_get_attribute(Object(craft\web\twig\Environment), Object(Twig\Source), Object(craft\models\FieldLayout), 'createForm', Array, 'method', false, false)
#27 /app/storage/runtime/compiled_templates/da/dabefed6ff1582e1dc9a4e76a1d80ab2e540117b0f08e1a9614bb2e80fe18708.php(177): craft\helpers\Template::attribute(Object(craft\web\twig\Environment), Object(Twig\Source), Object(craft\models\FieldLayout), 'createForm', Array, 'method')
#28 /app/vendor/twig/twig/src/Template.php(405): __TwigTemplate_553859aeb0d04f25ea1a89336e5c81f607180b97375c17a92d0de95b10111e7c->doDisplay(Array, Array)
#29 /app/vendor/twig/twig/src/Template.php(378): Twig\Template->displayWithErrorHandling(Array, Array)
#30 /app/storage/runtime/compiled_templates/49/4935a3ada1578bac4b9a6b53ded421bb97c7d78368e368eaa45a2291483c7b89.php(124): Twig\Template->display(Array, Array)
#31 /app/vendor/twig/twig/src/Template.php(405): __TwigTemplate_6772be95b52c9e7cdc4b1e1ce54ca8ff8f9393ef5b402111bbaf86fe64443323->doDisplay(Array, Array)
#32 /app/vendor/twig/twig/src/Template.php(378): Twig\Template->displayWithErrorHandling(Array, Array)
#33 /app/vendor/twig/twig/src/Template.php(390): Twig\Template->display(Array)
#34 /app/vendor/twig/twig/src/TemplateWrapper.php(45): Twig\Template->render(Array, Array)
#35 /app/vendor/twig/twig/src/Environment.php(318): Twig\TemplateWrapper->render(Array)
#36 /app/vendor/craftcms/cms/src/web/View.php(408): Twig\Environment->render('entries/_edit', Array)
#37 /app/vendor/craftcms/cms/src/web/View.php(461): craft\web\View->renderTemplate('entries/_edit', Array)
#38 /app/vendor/craftcms/cms/src/web/Controller.php(201): craft\web\View->renderPageTemplate('entries/_edit', Array, 'cp')
#39 /app/vendor/craftcms/cms/src/controllers/EntriesController.php(257): craft\web\Controller->renderTemplate('entries/_edit', Array)
#40 [internal function]: craft\controllers\EntriesController->actionEditEntry(Object(craft\models\Section), 5, NULL, NULL, Object(craft\models\Site), Object(craft\elements\Entry))
#41 /app/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#42 /app/vendor/yiisoft/yii2/base/Controller.php(178): yii\base\InlineAction->runWithParams(Array)
#43 /app/vendor/yiisoft/yii2/base/Module.php(552): yii\base\Controller->runAction('edit-entry', Array)
#44 /app/vendor/craftcms/cms/src/web/Application.php(287): yii\base\Module->runAction('entries/edit-en...', Array)
#45 /app/vendor/yiisoft/yii2/web/Application.php(103): craft\web\Application->runAction('entries/edit-en...', Array)
#46 /app/vendor/craftcms/cms/src/web/Application.php(272): yii\web\Application->handleRequest(Object(craft\web\Request))
#47 /app/vendor/yiisoft/yii2/base/Application.php(384): craft\web\Application->handleRequest(Object(craft\web\Request))
#48 /app/web/index.php(12): yii\base\Application->run()
#49 {main}

Expected behavior

I would expect the data from the renamed matrix field might be missing, but that the entry is still editable. Same as changing the handle of a matrix block's field outside of Vizy.

The same problem happens when trying to view a previous revision that has matrix data.

To work around this problem, I had to delete all occurrences of the Vizy blocks that used the matrix and recreate them after I changed the matrix block's field handle.

Steps to reproduce

  1. Create a matrix field with a block type and a field handle.
  2. Add this matrix to Vizy field.
  3. Add Vizy field to a section.
  4. Create and entry in that section that uses the matrix field inside Vizy.
  5. Rename the field handle inside the matrix field.
  6. Edit the entry.

Additional info

Additional context

engram-design commented 2 years ago

Ah yes, this might be an issue, due to Matrix's lack of handling of this. In Vizy we handle this differently to Craft itself does I believe. But this should be handled gracefully already (thanks to a PR), but looks like that's incorrectly implemented.

Fixed for the next release. To get the fix early, change your verbb/vizy requirement in composer.json to:

"require": {
  "verbb/vizy": "dev-craft-3 as 1.0.9",
  "...": "..."
}

Then run composer update.

For the moment, content is discarded, unlike a standalone Matrix field, purely because of how Matrix field content is stored against other elements (relationally as opposed to a JSON blob like Vizy). It's doable to update every single block to reference the newly renamed field, just a bit of work.

engram-design commented 2 years ago

Fixed in 1.0.10