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-07-26 08:15:15 +02:00
|
|
|
)->setTitleField('MenuTitle'),
|
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')));
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|