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;
|
2017-08-03 03:32:14 +02:00
|
|
|
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'
|
2017-11-16 02:43:32 +01:00
|
|
|
)
|
|
|
|
->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')
|
|
|
|
),
|
|
|
|
]);
|
|
|
|
|
2017-08-03 03:32:14 +02:00
|
|
|
if ($context['RequireLinkText']) {
|
|
|
|
$fields->insertAfter('PageID', TextField::create('Text', _t(__CLASS__.'.LINKTEXT', 'Link text')));
|
|
|
|
}
|
|
|
|
|
2018-09-25 16:48:49 +02:00
|
|
|
$this->extend('updateFormFields', $fields, $controller, $name, $context);
|
|
|
|
|
2017-05-25 07:29:32 +02:00
|
|
|
return $fields;
|
|
|
|
}
|
2017-08-03 03:32:14 +02:00
|
|
|
|
|
|
|
protected function getValidator($controller, $name, $context)
|
|
|
|
{
|
|
|
|
if ($context['RequireLinkText']) {
|
|
|
|
return RequiredFields::create('Text');
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
2017-05-25 07:29:32 +02:00
|
|
|
}
|