From 790c561cca07f39f62412df3f247c6d6faa9e82d Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Wed, 31 Jan 2024 10:30:00 +1300 Subject: [PATCH 1/2] FIX Elemental non-inline editing --- src/Form/Traits/LinkFieldGetOwnerTrait.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Form/Traits/LinkFieldGetOwnerTrait.php b/src/Form/Traits/LinkFieldGetOwnerTrait.php index 8740c844..62719df6 100644 --- a/src/Form/Traits/LinkFieldGetOwnerTrait.php +++ b/src/Form/Traits/LinkFieldGetOwnerTrait.php @@ -27,8 +27,12 @@ private function getOwnerFields(): array $relation = $this->getName(); // Elemental content block if (class_exists(BaseElement::class) && is_a($owner, BaseElement::class)) { + // Remove namespaces from inline editable blocks + // This will return an empty array for non-inline editable blocks (e.g. blocks in a gridfield) $arr = ElementalAreaController::removeNamespacesFromFields([$relation => ''], $owner->ID); - $relation = array_keys($arr)[0]; + if (array_key_exists(0, $arr)) { + $relation = array_keys($arr)[0]; + } } return [ 'ID' => $owner->ID, From 09f637c26384069db0cc8749f619c50c67336403 Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Wed, 31 Jan 2024 16:21:19 +1300 Subject: [PATCH 2/2] FIX Add HasOneRelationFieldInterface to LinkField --- src/Form/LinkField.php | 3 ++- src/Form/Traits/LinkFieldGetOwnerTrait.php | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Form/LinkField.php b/src/Form/LinkField.php index fcc5eeaa..fef8deac 100644 --- a/src/Form/LinkField.php +++ b/src/Form/LinkField.php @@ -6,11 +6,12 @@ use SilverStripe\LinkField\Models\Link; use SilverStripe\LinkField\Form\Traits\AllowedLinkClassesTrait; use SilverStripe\LinkField\Form\Traits\LinkFieldGetOwnerTrait; +use SilverStripe\Forms\HasOneRelationFieldInterface; /** * Allows CMS users to edit a Link object. */ -class LinkField extends FormField +class LinkField extends FormField implements HasOneRelationFieldInterface { use AllowedLinkClassesTrait; use LinkFieldGetOwnerTrait; diff --git a/src/Form/Traits/LinkFieldGetOwnerTrait.php b/src/Form/Traits/LinkFieldGetOwnerTrait.php index 62719df6..575a4bf2 100644 --- a/src/Form/Traits/LinkFieldGetOwnerTrait.php +++ b/src/Form/Traits/LinkFieldGetOwnerTrait.php @@ -30,8 +30,8 @@ private function getOwnerFields(): array // Remove namespaces from inline editable blocks // This will return an empty array for non-inline editable blocks (e.g. blocks in a gridfield) $arr = ElementalAreaController::removeNamespacesFromFields([$relation => ''], $owner->ID); - if (array_key_exists(0, $arr)) { - $relation = array_keys($arr)[0]; + if (!empty($arr)) { + $relation = array_key_first($arr); } } return [