2024-02-13 02:27:18 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
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\EmailLink;
|
|
|
|
use SilverStripe\LinkField\Models\PhoneLink;
|
|
|
|
use SilverStripe\LinkField\Models\SiteTreeLink;
|
|
|
|
|
|
|
|
class LinkPageExtension extends Extension
|
|
|
|
{
|
|
|
|
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)
|
|
|
|
{
|
2024-02-29 02:33:36 +01:00
|
|
|
$fields->removeByName(['Content', 'HasOneLinkID', 'HasManyLinksID']);
|
2024-02-13 02:27:18 +01:00
|
|
|
|
|
|
|
$fields->addFieldsToTab(
|
|
|
|
'Root.Main',
|
|
|
|
[
|
2024-02-29 02:33:36 +01:00
|
|
|
LinkField::create('HasOneLink', 'Single Link')
|
2024-02-13 02:27:18 +01:00
|
|
|
->setAllowedTypes([
|
|
|
|
SiteTreeLink::class,
|
|
|
|
EmailLink::class,
|
|
|
|
PhoneLink::class
|
|
|
|
]),
|
2024-02-29 02:33:36 +01:00
|
|
|
MultiLinkField::create('HasManyLinks', 'Multiple Links'),
|
2024-02-13 02:27:18 +01:00
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|