From e279e5a0b682cab127c9e8681433b707b1387423 Mon Sep 17 00:00:00 2001 From: Guy Sartorelli <36352093+GuySartorelli@users.noreply.github.com> Date: Thu, 27 Jun 2024 09:45:08 +1200 Subject: [PATCH] ENH Take advantage of auto-scaffolded formfields for link (#190) --- code/elemental/ElementContentExtension.php | 8 +++++++- .../linkfield/Extensions/CompanyExtension.php | 13 +----------- .../Extensions/ElementContentExtension.php | 20 +++++-------------- .../Extensions/LinkPageExtension.php | 2 +- 4 files changed, 14 insertions(+), 29 deletions(-) diff --git a/code/elemental/ElementContentExtension.php b/code/elemental/ElementContentExtension.php index d813fdd..6325ef6 100644 --- a/code/elemental/ElementContentExtension.php +++ b/code/elemental/ElementContentExtension.php @@ -10,6 +10,7 @@ use SilverStripe\ORM\ValidationResult; use SilverStripe\Forms\CompositeValidator; use SilverStripe\Forms\NumericField; use SilverStripe\Forms\RequiredFields; +use SilverStripe\Forms\SearchableDropdownField; use SilverStripe\Forms\TextField; /** @@ -47,7 +48,12 @@ class ElementContentExtension extends Extension protected function updateCMSFields(FieldList $fields) { - $fields->removeByName('HTML'); + // Note we explicitly use a SearchableDropdownField here so the behat test can rely on specific selectors + $fields->removeByName(['HTML', 'MyPage', 'MyPageID']); + $fields->addFieldToTab( + 'Root.Main', + SearchableDropdownField::create('MyPageID', 'My page', SiteTree::get())->setIsLazyLoaded(false) + ); $fields->addFieldToTab('Root.Main', TextField::create('MyField', 'My Field')); $fields->addFieldToTab('Root.Main', NumericField::create('MyInt', 'My Int')); } diff --git a/code/linkfield/Extensions/CompanyExtension.php b/code/linkfield/Extensions/CompanyExtension.php index b6303b6..18b9e2e 100644 --- a/code/linkfield/Extensions/CompanyExtension.php +++ b/code/linkfield/Extensions/CompanyExtension.php @@ -5,8 +5,6 @@ namespace SilverStripe\FrameworkTest\LinkField\Extensions; use SilverStripe\Core\Extension; use SilverStripe\Forms\FieldList; use SilverStripe\LinkField\Models\Link; -use SilverStripe\LinkField\Form\LinkField; -use SilverStripe\LinkField\Form\MultiLinkField; use SilverStripe\LinkField\Models\ExternalLink; class CompanyExtension extends Extension @@ -36,15 +34,6 @@ class CompanyExtension extends Extension protected function updateCMSFields(FieldList $fields) { - $fields->removeByName(['CompanyWebSiteLinkID', 'ManyCompanyWebSiteLinkID']); - - $fields->addFieldsToTab( - 'Root.Main', - [ - LinkField::create('CompanyWebSiteLink', 'Company Website link') - ->setAllowedTypes([ExternalLink::class]), - MultiLinkField::create('ManyCompanyWebSiteLink', 'Multiple Company Website link'), - ] - ); + $fields->dataFieldByName('CompanyWebSiteLink')->setAllowedTypes([ExternalLink::class]); } } diff --git a/code/linkfield/Extensions/ElementContentExtension.php b/code/linkfield/Extensions/ElementContentExtension.php index d7a43a1..350ed45 100644 --- a/code/linkfield/Extensions/ElementContentExtension.php +++ b/code/linkfield/Extensions/ElementContentExtension.php @@ -3,8 +3,6 @@ namespace SilverStripe\FrameworkTest\LinkField\Extensions; use SilverStripe\Core\Extension; -use SilverStripe\LinkField\Form\LinkField; -use SilverStripe\LinkField\Form\MultiLinkField; use SilverStripe\LinkField\Models\Link; use SilverStripe\LinkField\Models\EmailLink; use SilverStripe\LinkField\Models\PhoneLink; @@ -39,18 +37,10 @@ class ElementContentExtension extends Extension protected function updateCMSFields($fields) { - $fields->removeByName(['OneLinkID', 'ManyLinks']); - $fields->addFieldsToTab( - 'Root.Main', - [ - LinkField::create('OneLink', 'Single Link') - ->setAllowedTypes([ - SiteTreeLink::class, - EmailLink::class, - PhoneLink::class - ]), - MultiLinkField::create('ManyLinks', 'Multiple Links'), - ], - ); + $fields->dataFieldByName('OneLink')->setAllowedTypes([ + SiteTreeLink::class, + EmailLink::class, + PhoneLink::class + ]); } } diff --git a/code/linkfield/Extensions/LinkPageExtension.php b/code/linkfield/Extensions/LinkPageExtension.php index 9e9aa98..4cffe03 100644 --- a/code/linkfield/Extensions/LinkPageExtension.php +++ b/code/linkfield/Extensions/LinkPageExtension.php @@ -38,7 +38,7 @@ class LinkPageExtension extends Extension protected function updateCMSFields(FieldList $fields) { - $fields->removeByName(['Content', 'HasOneLinkID', 'HasManyLinksID']); + $fields->removeByName(['Content']); $fields->addFieldsToTab( 'Root.Main',