1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SilverStripe\ElementalBlocks\Form; |
4
|
|
|
|
5
|
|
|
use SilverStripe\CMS\Model\SiteTree; |
6
|
|
|
use SilverStripe\Forms\CheckboxField_Readonly; |
7
|
|
|
use SilverStripe\Forms\FieldList; |
8
|
|
|
use SilverStripe\Forms\ReadonlyField; |
9
|
|
|
use SilverStripe\Forms\TextField; |
10
|
|
|
use SilverStripe\Forms\ToggleCompositeField; |
11
|
|
|
use SilverStripe\Forms\TreeDropdownField; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Readonly version of a {@link BlockLinkField} field, which displays the data fields as readonly text |
15
|
|
|
* inputs and a checkbox for "target blank". |
16
|
|
|
*/ |
17
|
|
|
class BlockLinkField_Readonly extends ReadonlyField |
18
|
|
|
{ |
19
|
|
|
public function Field($properties = []) |
20
|
|
|
{ |
21
|
|
|
/** @var BlockLinkField $originalField */ |
22
|
|
|
$originalField = BlockLinkField::create('TempReadonly')->setValue($this->value); |
|
|
|
|
23
|
|
|
|
24
|
|
|
$name = $this->getName(); |
25
|
|
|
|
26
|
|
|
$fields = FieldList::create(); |
27
|
|
|
|
28
|
|
|
$fields->push( |
29
|
|
|
TreeDropdownField::create($name . '_PageID', null, SiteTree::class) |
30
|
|
|
->setTitle(_t('SilverStripe\\ElementalBlocks\\Form\\BlockLinkField.SelectPage', 'Select a page')) |
31
|
|
|
->setValue($originalField->getParsedValue()->PageID) |
32
|
|
|
->performReadonlyTransformation() |
33
|
|
|
); |
34
|
|
|
|
35
|
|
|
if ($originalField->getShowLinkText()) { |
36
|
|
|
$fields->push( |
37
|
|
|
$this->castedCopy(TextField::class) |
38
|
|
|
->setName($name . '_Text') |
39
|
|
|
->setTitle(_t('SilverStripe\\ElementalBlocks\\Form\\BlockLinkField.LinkText', 'Link text')) |
40
|
|
|
->setValue($originalField->getLinkText()) |
41
|
|
|
); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
$fields->push( |
45
|
|
|
$this->castedCopy(TextField::class) |
46
|
|
|
->setName($name . '_Description') |
47
|
|
|
->setTitle(_t('SilverStripe\\ElementalBlocks\\Form\\BlockLinkField.Description', 'Link description')) |
48
|
|
|
->setValue($originalField->getLinkDescription()) |
49
|
|
|
); |
50
|
|
|
|
51
|
|
|
$fields->push( |
52
|
|
|
$this->castedCopy(CheckboxField_Readonly::class) |
53
|
|
|
->setName($name . '_TargetBlank') |
54
|
|
|
->setTitle( |
55
|
|
|
_t('SilverStripe\\ElementalBlocks\\Form\\BlockLinkField.TargetBlank', 'Open in a new window/tab') |
56
|
|
|
) |
57
|
|
|
->setValue($originalField->getLinkTargetBlank()) |
58
|
|
|
); |
59
|
|
|
|
60
|
|
|
$fields->each(function ($field) { |
61
|
|
|
$field->setReadonly(true); |
62
|
|
|
}); |
63
|
|
|
|
64
|
|
|
return ToggleCompositeField::create($name . '_Readonly', $this->Title(), $fields); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Do not render a form field holder for this, just display the toggled composite field |
69
|
|
|
* |
70
|
|
|
* {@inheritDoc} |
71
|
|
|
*/ |
72
|
|
|
public function FieldHolder($properties = []) |
73
|
|
|
{ |
74
|
|
|
return $this->Field($properties); |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|