Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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']);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Formfields aren't autoscaffolded for SiteTree which this extension is made for.


$fields->addFieldsToTab(
'Root.Main',
Expand Down