From 36f7ad7ebe150167f52bec8b22820963e2d4004f Mon Sep 17 00:00:00 2001 From: Dennis Ruiter Date: Thu, 11 May 2023 19:50:21 +0200 Subject: [PATCH] Child widget fields should now properly propagate to the related widget --- composer.json | 3 ++- src/Element/ElementWidget.php | 9 ++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index c01b172..7a638fb 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,8 @@ "silverstripe/cms": "^4.11", "dnadesign/silverstripe-elemental": "^4.9", "sheadawson/silverstripe-dependentdropdownfield": "^2", - "unclecheese/display-logic": "^2.0" + "unclecheese/display-logic": "^2.0", + "stevie-mayhew/hasoneedit": "^2.0" }, "require-dev": { "friendsofphp/php-cs-fixer": "^3.4" diff --git a/src/Element/ElementWidget.php b/src/Element/ElementWidget.php index c011a00..fb34bff 100644 --- a/src/Element/ElementWidget.php +++ b/src/Element/ElementWidget.php @@ -5,6 +5,7 @@ namespace WeDevelop\ElementalWidget\Element; use DNADesign\Elemental\Models\BaseElement; +use SGN\HasOneEdit\HasOneEdit; use Sheadawson\DependentDropdown\Forms\DependentDropdownField; use SilverStripe\Core\ClassInfo; use SilverStripe\Core\Config\Config; @@ -122,9 +123,15 @@ public function getCMSFields(): FieldList $widgetFields->removeByName([ 'Title', - 'Root.Main', + 'Main', ]); + // We'll loop over the widget fields to properly set the name so it maps to the relation + // instead of trying to edit it on the element itself + foreach($widgetFields->dataFields() as $field) { + $field->setName('Widget' . HasOneEdit::FIELD_SEPARATOR . $field->getName()); + } + if ($this->SourcesFromCollection) { $fields->addFieldToTab( 'Root.Widget',