From f8eac086d24071e33e70da90db20206a19a9a733 Mon Sep 17 00:00:00 2001 From: Sabina Talipova <87288324+sabina-talipova@users.noreply.github.com> Date: Tue, 13 Feb 2024 14:27:18 +1300 Subject: [PATCH] MNT Behat test LinkField page and LinkField block (#162) --- .../Extensions/ElementContentExtension.php | 57 +++++++++++++++++++ .../Extensions/LinkPageExtension.php | 56 ++++++++++++++++++ 2 files changed, 113 insertions(+) create mode 100644 code/linkfield/Extensions/ElementContentExtension.php create mode 100644 code/linkfield/Extensions/LinkPageExtension.php diff --git a/code/linkfield/Extensions/ElementContentExtension.php b/code/linkfield/Extensions/ElementContentExtension.php new file mode 100644 index 0000000..a1c2093 --- /dev/null +++ b/code/linkfield/Extensions/ElementContentExtension.php @@ -0,0 +1,57 @@ + Link::class, + ]; + + private static $has_many = [ + 'ManyLinks' => Link::class . '.Owner', + ]; + + private static array $owns = [ + 'OneLink', + 'ManyLinks', + ]; + + private static array $cascade_deletes = [ + 'OneLink', + 'ManyLinks', + ]; + + private static array $cascade_duplicates = [ + 'OneLink', + 'ManyLinks', + ]; + + public function updateCMSFields($fields) + { + $fields->removeByName(['OneLinkID', 'ManyLinks']); + $fields->addFieldsToTab( + 'Root.Main', + [ + LinkField::create('OneLink') + ->setAllowedTypes([ + SiteTreeLink::class, + EmailLink::class, + PhoneLink::class + ]), + MultiLinkField::create('ManyLinks'), + ], + ); + } +} diff --git a/code/linkfield/Extensions/LinkPageExtension.php b/code/linkfield/Extensions/LinkPageExtension.php new file mode 100644 index 0000000..3dc027a --- /dev/null +++ b/code/linkfield/Extensions/LinkPageExtension.php @@ -0,0 +1,56 @@ + Link::class, + ]; + + private static $has_many = [ + 'HasManyLinks' => Link::class . '.Owner', + ]; + + private static array $owns = [ + 'HasOneLink', + 'HasManyLinks', + ]; + + private static array $cascade_deletes = [ + 'HasOneLink', + 'HasManyLinks', + ]; + + private static array $cascade_duplicates = [ + 'HasOneLink', + 'HasManyLinks', + ]; + + public function updateCMSFields(FieldList $fields) + { + $fields->removeByName(['Content', 'HasOneLinkID', 'HasManyLinks']); + + $fields->addFieldsToTab( + 'Root.Main', + [ + LinkField::create('HasOneLink') + ->setAllowedTypes([ + SiteTreeLink::class, + EmailLink::class, + PhoneLink::class + ]), + MultiLinkField::create('HasManyLinks'), + ], + ); + } +}