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 d08de7d commit e8dc065
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 28 deletions.
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 e8dc065

Please sign in to comment.