silverstripe-cms/code/Forms/InternalLinkFormFactory.php

63 lines
1.7 KiB
PHP
Raw Normal View History

2017-05-25 07:29:32 +02:00
<?php
namespace SilverStripe\CMS\Forms;
use SilverStripe\Admin\Forms\LinkFormFactory;
use SilverStripe\CMS\Model\SiteTree;
2017-09-05 04:38:38 +02:00
use SilverStripe\Control\RequestHandler;
2017-05-25 07:29:32 +02:00
use SilverStripe\Forms\CheckboxField;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\TextField;
use SilverStripe\Forms\TreeDropdownField;
use SilverStripe\Forms\RequiredFields;
2017-05-25 07:29:32 +02:00
/**
* Provides a form factory for inserting internal page links in a HTML editor
*/
class InternalLinkFormFactory extends LinkFormFactory
{
2017-09-05 04:38:38 +02:00
/**
* @param RequestHandler $controller
* @param string $name
* @param array $context
* @return FieldList
*/
2017-05-25 07:29:32 +02:00
protected function getFormFields($controller, $name, $context)
{
$fields = FieldList::create([
TreeDropdownField::create(
'PageID',
_t(__CLASS__.'.SELECT_PAGE', 'Select a page'),
SiteTree::class,
'ID',
'TreeTitle'
)
->setTitleField('MenuTitle')
->setHasEmptyDefault(true),
2017-05-25 07:29:32 +02:00
TextField::create(
'Description',
_t(__CLASS__.'.LINKDESCR', 'Link description')
),
CheckboxField::create(
'TargetBlank',
_t(__CLASS__.'.LINKOPENNEWWIN', 'Open in new window/tab')
),
]);
if ($context['RequireLinkText']) {
$fields->insertAfter('PageID', TextField::create('Text', _t(__CLASS__.'.LINKTEXT', 'Link text')));
}
2017-05-25 07:29:32 +02:00
return $fields;
}
protected function getValidator($controller, $name, $context)
{
if ($context['RequireLinkText']) {
return RequiredFields::create('Text');
}
return null;
}
2017-05-25 07:29:32 +02:00
}