ENH Take advantage of auto-scaffolded formfields for link (#190)

This commit is contained in:
Guy Sartorelli 2024-06-27 09:45:08 +12:00 committed by GitHub
parent a51b65b336
commit e279e5a0b6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 14 additions and 29 deletions

View File

@ -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'));
}

View File

@ -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]);
}
}

View File

@ -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
]);
}
}

View File

@ -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',