diff --git a/_config/extensions.yml b/_config/extensions.yml index 8ff7300..3bd2790 100644 --- a/_config/extensions.yml +++ b/_config/extensions.yml @@ -43,3 +43,20 @@ SilverStripe\FrameworkTest\Elemental\Model\ElementalBehatTestObject: BasicElementalPage: extensions: - DNADesign\Elemental\Extensions\ElementalPageExtension + +--- +Only: + moduleexists: 'silverstripe/linkfield' +--- + +SilverStripe\FrameworkTest\LinkField\PageTypes\LinkFieldTestPage: + extensions: + - SilverStripe\FrameworkTest\LinkField\Extensions\LinkPageExtension + +SilverStripe\FrameworkTest\Model\Company: + extensions: + - SilverStripe\FrameworkTest\LinkField\Extensions\CompanyExtension + +SilverStripe\FrameworkTest\LinkField\Blocks\LinkFieldTestBlock: + extensions: + - SilverStripe\FrameworkTest\LinkField\Extensions\ElementContentExtension diff --git a/code/linkfield/Blocks/LinkFieldTestBlock.php b/code/linkfield/Blocks/LinkFieldTestBlock.php new file mode 100644 index 0000000..e36e3b7 --- /dev/null +++ b/code/linkfield/Blocks/LinkFieldTestBlock.php @@ -0,0 +1,16 @@ + Link::class, + ]; + + private static $has_many = [ + 'ManyCompanyWebSiteLink' => Link::class . '.Owner', + ]; + + private static array $owns = [ + 'CompanyWebSiteLink', + 'ManyCompanyWebSiteLink', + ]; + + private static array $cascade_deletes = [ + 'CompanyWebSiteLink', + 'ManyCompanyWebSiteLink', + ]; + + private static array $cascade_duplicates = [ + 'CompanyWebSiteLink', + 'ManyCompanyWebSiteLink', + ]; + + public 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'), + ] + ); + } +} diff --git a/code/linkfield/Extensions/ElementContentExtension.php b/code/linkfield/Extensions/ElementContentExtension.php index a1c2093..ca02ac6 100644 --- a/code/linkfield/Extensions/ElementContentExtension.php +++ b/code/linkfield/Extensions/ElementContentExtension.php @@ -12,7 +12,6 @@ use SilverStripe\LinkField\Models\SiteTreeLink; class ElementContentExtension extends Extension { - private static bool $inline_editable = true; private static array $has_one = [ @@ -44,13 +43,13 @@ class ElementContentExtension extends Extension $fields->addFieldsToTab( 'Root.Main', [ - LinkField::create('OneLink') + LinkField::create('OneLink', 'Single Link') ->setAllowedTypes([ SiteTreeLink::class, EmailLink::class, PhoneLink::class ]), - MultiLinkField::create('ManyLinks'), + MultiLinkField::create('ManyLinks', 'Multiple Links'), ], ); } diff --git a/code/linkfield/Extensions/LinkPageExtension.php b/code/linkfield/Extensions/LinkPageExtension.php index 3dc027a..b564c34 100644 --- a/code/linkfield/Extensions/LinkPageExtension.php +++ b/code/linkfield/Extensions/LinkPageExtension.php @@ -38,18 +38,18 @@ class LinkPageExtension extends Extension public function updateCMSFields(FieldList $fields) { - $fields->removeByName(['Content', 'HasOneLinkID', 'HasManyLinks']); + $fields->removeByName(['Content', 'HasOneLinkID', 'HasManyLinksID']); $fields->addFieldsToTab( 'Root.Main', [ - LinkField::create('HasOneLink') + LinkField::create('HasOneLink', 'Single Link') ->setAllowedTypes([ SiteTreeLink::class, EmailLink::class, PhoneLink::class ]), - MultiLinkField::create('HasManyLinks'), + MultiLinkField::create('HasManyLinks', 'Multiple Links'), ], ); } diff --git a/code/linkfield/PageTypes/LinkFieldTestPage.php b/code/linkfield/PageTypes/LinkFieldTestPage.php new file mode 100644 index 0000000..f699b93 --- /dev/null +++ b/code/linkfield/PageTypes/LinkFieldTestPage.php @@ -0,0 +1,10 @@ + +
+

Single Link

+ <% with $OneLink %> + <% if $exists %> + target="_blank" rel="noopener noreferrer"<% end_if %>>$Title + <% end_if %> + <% end_with %> +
+<% end_if %> + +<% if $ManyLinks %> +
+

Multiple Link

+ +
+<% end_if %> diff --git a/templates/SilverStripe/FrameworkTest/LinkField/PageTypes/Layout/LinkFieldTestPage.ss b/templates/SilverStripe/FrameworkTest/LinkField/PageTypes/Layout/LinkFieldTestPage.ss new file mode 100644 index 0000000..47e2265 --- /dev/null +++ b/templates/SilverStripe/FrameworkTest/LinkField/PageTypes/Layout/LinkFieldTestPage.ss @@ -0,0 +1,34 @@ +
+
+
+
+
+

$Title.XML

+ + <% if $HasOneLink %> +
+

Single Link

+ <% with $HasOneLink %> + <% if $exists %> + target="_blank" rel="noopener noreferrer"<% end_if %>>$Title + <% end_if %> + <% end_with %> +
+ <% end_if %> + + + <% if $HasManyLinks %> +
+

Multiple Link

+
    + <% loop $HasManyLinks %> +
  • $Me
  • + <% end_loop %> +
+
+ <% end_if %> +
+
+
+
+