|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace SilverStripe\CMS\Forms; |
|
4
|
|
|
|
|
5
|
|
|
use SilverStripe\Admin\Forms\LinkFormFactory; |
|
6
|
|
|
use SilverStripe\CMS\Model\SiteTree; |
|
7
|
|
|
use SilverStripe\Forms\CheckboxField; |
|
8
|
|
|
use SilverStripe\Forms\FieldList; |
|
9
|
|
|
use SilverStripe\Forms\TextField; |
|
10
|
|
|
use SilverStripe\Forms\TreeDropdownField; |
|
11
|
|
|
use SilverStripe\Forms\RequiredFields; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Provides a form factory for inserting internal page links in a HTML editor |
|
15
|
|
|
*/ |
|
16
|
|
|
class InternalLinkFormFactory extends LinkFormFactory |
|
17
|
|
|
{ |
|
18
|
|
|
protected function getFormFields($controller, $name, $context) |
|
19
|
|
|
{ |
|
20
|
|
|
$fields = FieldList::create([ |
|
21
|
|
|
TreeDropdownField::create( |
|
22
|
|
|
'PageID', |
|
23
|
|
|
_t(__CLASS__.'.SELECT_PAGE', 'Select a page'), |
|
24
|
|
|
SiteTree::class, |
|
25
|
|
|
'ID', |
|
26
|
|
|
'TreeTitle' |
|
27
|
|
|
)->setTitleField('MenuTitle'), |
|
28
|
|
|
TextField::create( |
|
29
|
|
|
'Description', |
|
30
|
|
|
_t(__CLASS__.'.LINKDESCR', 'Link description') |
|
31
|
|
|
), |
|
32
|
|
|
TextField::create('Anchor', _t(__CLASS__.'.ANCHORVALUE', 'Anchor')), |
|
33
|
|
|
CheckboxField::create( |
|
34
|
|
|
'TargetBlank', |
|
35
|
|
|
_t(__CLASS__.'.LINKOPENNEWWIN', 'Open in new window/tab') |
|
36
|
|
|
), |
|
37
|
|
|
]); |
|
38
|
|
|
|
|
39
|
|
|
if ($context['RequireLinkText']) { |
|
40
|
|
|
$fields->insertAfter('PageID', TextField::create('Text', _t(__CLASS__.'.LINKTEXT', 'Link text'))); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
return $fields; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
protected function getValidator($controller, $name, $context) |
|
47
|
|
|
{ |
|
48
|
|
|
if ($context['RequireLinkText']) { |
|
49
|
|
|
return RequiredFields::create('Text'); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
return null; |
|
53
|
|
|
} |
|
54
|
|
|
} |
|
55
|
|
|
|