-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MNT Behat test LinkField page and LinkField block
- Loading branch information
Sabina Talipova
committed
Feb 7, 2024
1 parent
7c1c85f
commit 04f6755
Showing
2 changed files
with
133 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<?php | ||
|
||
namespace SilverStripe\FrameworkTest\LinkField\Blocks; | ||
|
||
use DNADesign\Elemental\Models\BaseElement; | ||
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; | ||
use SilverStripe\LinkField\Models\SiteTreeLink; | ||
|
||
class LinksListBlock extends BaseElement | ||
{ | ||
private static string $icon = 'font-icon-block-file-list'; | ||
|
||
private static string $table_name = 'LinksListBlock'; | ||
|
||
private static string $singular_name = 'Links List Block'; | ||
|
||
private static string $plural_name = 'Links List Blocks'; | ||
|
||
private static string $description = 'Displays a set of links which can be internal page links, external urls or ' | ||
. 'file links.'; | ||
|
||
private static bool $inline_editable = true; | ||
|
||
private static array $has_one = [ | ||
'OneLink' => Link::class, | ||
]; | ||
|
||
private static $has_many = [ | ||
'ManyLinks' => Link::class . '.Owner', | ||
]; | ||
|
||
private static array $owns = [ | ||
'OneLink', | ||
'ManyLinks', | ||
]; | ||
|
||
private static array $cascade_deletes = [ | ||
'OneLink', | ||
'ManyLinks', | ||
]; | ||
|
||
private static array $cascade_duplicates = [ | ||
'OneLink', | ||
'ManyLinks', | ||
]; | ||
|
||
public function getType(): string | ||
{ | ||
return _t(self::class . '.BlockType', 'Links List'); | ||
} | ||
|
||
public function getCMSFields() | ||
{ | ||
$fields = parent::getCMSFields(); | ||
|
||
$fields->removeByName(['OneLinkID', 'ManyLinks']); | ||
|
||
$fields->addFieldsToTab( | ||
'Root.Main', | ||
[ | ||
LinkField::create('OneLink') | ||
->setAllowedTypes([ | ||
SiteTreeLink::class, | ||
EmailLink::class, | ||
PhoneLink::class | ||
]), | ||
MultiLinkField::create('ManyLinks'), | ||
], | ||
); | ||
|
||
return $fields; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
|
||
namespace SilverStripe\FrameworkTest\LinkField\Extensions; | ||
|
||
use SilverStripe\Forms\FieldList; | ||
use SilverStripe\LinkField\Models\Link; | ||
use SilverStripe\LinkField\Form\LinkField; | ||
use SilverStripe\LinkField\Form\MultiLinkField; | ||
use SilverStripe\LinkField\Models\EmailLink; | ||
use SilverStripe\LinkField\Models\PhoneLink; | ||
use SilverStripe\LinkField\Models\SiteTreeLink; | ||
use SilverStripe\ORM\DataExtension; | ||
|
||
class LinkPageExtension extends DataExtension | ||
{ | ||
private static array $has_one = [ | ||
'HasOneLink' => Link::class, | ||
]; | ||
|
||
private static $has_many = [ | ||
'HasManyLinks' => Link::class . '.Owner', | ||
]; | ||
|
||
private static array $owns = [ | ||
'HasOneLink', | ||
'HasManyLinks', | ||
]; | ||
|
||
private static array $cascade_deletes = [ | ||
'HasOneLink', | ||
'HasManyLinks', | ||
]; | ||
|
||
private static array $cascade_duplicates = [ | ||
'HasOneLink', | ||
'HasManyLinks', | ||
]; | ||
|
||
public function updateCMSFields(FieldList $fields) | ||
{ | ||
$fields->removeByName(['Content', 'HasOneLinkID', 'HasManyLinks']); | ||
|
||
$fields->addFieldsToTab( | ||
'Root.Main', | ||
[ | ||
LinkField::create('HasOneLink') | ||
->setAllowedTypes([ | ||
SiteTreeLink::class, | ||
EmailLink::class, | ||
PhoneLink::class | ||
]), | ||
MultiLinkField::create('HasManyLinks'), | ||
], | ||
); | ||
} | ||
} |