Skip to content

Commit

Permalink
ENH Take advantage of auto-scaffolded formfields for link
Browse files Browse the repository at this point in the history
  • Loading branch information
GuySartorelli committed Jun 24, 2024
1 parent a51b65b commit 865de81
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 29 deletions.
8 changes: 7 additions & 1 deletion code/elemental/ElementContentExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use SilverStripe\Forms\CompositeValidator;
use SilverStripe\Forms\NumericField;
use SilverStripe\Forms\RequiredFields;
use SilverStripe\Forms\SearchableDropdownField;
use SilverStripe\Forms\TextField;

/**
Expand Down Expand Up @@ -47,7 +48,12 @@ protected function updateCMSCompositeValidator(CompositeValidator $compositeVali

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'));
}
Expand Down
13 changes: 1 addition & 12 deletions code/linkfield/Extensions/CompanyExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
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
Expand Down Expand Up @@ -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]);
}
}
20 changes: 5 additions & 15 deletions code/linkfield/Extensions/ElementContentExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
]);
}
}
2 changes: 1 addition & 1 deletion code/linkfield/Extensions/LinkPageExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 865de81

Please sign in to comment.