1 | <?php |
||
10 | class EditableLiteralField extends EditableFormField |
||
|
|||
11 | { |
||
12 | |||
13 | private static $singular_name = 'HTML Block'; |
||
14 | |||
15 | private static $plural_name = 'HTML Blocks'; |
||
16 | |||
17 | /** |
||
18 | * Mark as literal only |
||
19 | * |
||
20 | * @config |
||
21 | * @var bool |
||
22 | */ |
||
23 | private static $literal = true; |
||
24 | |||
25 | /** |
||
26 | * Get the name of the editor config to use for HTML sanitisation. Defaults to the active config. |
||
27 | * |
||
28 | * @var string |
||
29 | * @config |
||
30 | */ |
||
31 | private static $editor_config = null; |
||
32 | |||
33 | private static $db = array( |
||
34 | 'Content' => 'HTMLText', // From CustomSettings |
||
35 | 'HideFromReports' => 'Boolean(0)', // from CustomSettings |
||
36 | 'HideLabel' => 'Boolean(0)' |
||
37 | ); |
||
38 | |||
39 | private static $defaults = array( |
||
40 | 'HideFromReports' => false |
||
41 | ); |
||
42 | |||
43 | /** |
||
44 | * Returns the {@see HtmlEditorConfig} instance to use for sanitisation |
||
45 | * |
||
46 | * @return HtmlEditorConfig |
||
47 | */ |
||
48 | 1 | protected function getEditorConfig() |
|
56 | |||
57 | /** |
||
58 | * Safely sanitise html content, if enabled |
||
59 | * |
||
60 | * @param string $content Raw html |
||
61 | * @return string Safely sanitised html |
||
62 | */ |
||
63 | 6 | protected function sanitiseContent($content) |
|
76 | |||
77 | /** |
||
78 | * Get HTML Content of this literal field |
||
79 | * |
||
80 | * @return string |
||
81 | */ |
||
82 | 6 | public function getContent() |
|
88 | |||
89 | /** |
||
90 | * Set the content with the given value |
||
91 | * |
||
92 | * @param string $content |
||
93 | */ |
||
94 | 1 | public function setContent($content) |
|
100 | |||
101 | /** |
||
102 | * @return FieldList |
||
103 | */ |
||
104 | public function getCMSFields() |
||
126 | |||
127 | 3 | public function getFormField() |
|
128 | { |
||
129 | 3 | $content = LiteralField::create( |
|
130 | 3 | "LiteralFieldContent-{$this->ID}]", |
|
131 | 3 | $this->dbObject('Content')->forTemplate() |
|
132 | 3 | ); |
|
133 | |||
134 | 3 | $field = CompositeField::create($content) |
|
135 | 3 | ->setName($this->Name) |
|
136 | 3 | ->setID($this->Name) |
|
137 | 3 | ->setFieldHolderTemplate('UserFormsLiteralField_holder'); |
|
138 | |||
139 | 3 | $this->doUpdateFormField($field); |
|
140 | |||
141 | 3 | return $field; |
|
142 | } |
||
143 | |||
144 | 2 | protected function updateFormField($field) |
|
145 | { |
||
146 | 2 | parent::updateFormField($field); |
|
147 | |||
148 | 2 | if ($this->HideLabel) { |
|
149 | 1 | $this->ExtraClass .= ' nolabel'; |
|
150 | 1 | } else { |
|
151 | 2 | $field->setTitle($this->Title); |
|
152 | } |
||
153 | 2 | } |
|
154 | |||
155 | public function showInReports() |
||
159 | } |
||
160 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.