1 | <?php |
||
10 | class ViewTemplatePageExtension extends DataExtension |
||
11 | { |
||
12 | /** |
||
13 | * Page setting field for module status. |
||
14 | * |
||
15 | * @var array |
||
16 | */ |
||
17 | private static $db = [ |
||
18 | 'EnableViewTemplate' => 'Boolean', |
||
19 | ]; |
||
20 | |||
21 | 4 | public function __construct() |
|
22 | { |
||
23 | 4 | parent::__construct(); |
|
24 | |||
25 | // This may get called before the schema is created. |
||
26 | 4 | if (!DB::get_schema()->isSchemaUpdating()) { |
|
27 | 3 | $htmlEditorNames = Config::inst()->get('ViewTemplate', 'htmleditor_names'); |
|
28 | 3 | if (is_array($htmlEditorNames)) { |
|
29 | 3 | foreach ($htmlEditorNames as $htmlEditorName) { |
|
30 | 3 | HtmlEditorConfig::get($htmlEditorName)->setOption('viewtemplate', ViewTemplate::get()->map('Title')->toArray()); |
|
31 | 3 | } |
|
32 | 3 | } |
|
33 | 3 | } |
|
34 | 4 | } |
|
35 | |||
36 | /** |
||
37 | * Override the Content property from the page object. |
||
38 | * |
||
39 | * @return string |
||
40 | */ |
||
41 | 2 | public function Content() |
|
42 | { |
||
43 | // Page content |
||
44 | 2 | $content = $this->owner->Content; |
|
45 | |||
46 | // Return original content |
||
47 | 2 | if (!$this->owner->EnableViewTemplate) { |
|
48 | 1 | return $content; |
|
49 | } |
||
50 | |||
51 | // Replace placeholders |
||
52 | 2 | return $this->replacePlaceholders($content); |
|
53 | } |
||
54 | |||
55 | /** |
||
56 | * Replaces placeholders within the $content property their actual value. |
||
57 | * |
||
58 | * @param string $content |
||
59 | * |
||
60 | * @return string |
||
61 | */ |
||
62 | 2 | public function replacePlaceholders($content) |
|
93 | |||
94 | /** |
||
95 | * Add an element to the page settings tab to set the status of this module (enabled or not enabled). |
||
96 | * |
||
97 | * @param \FieldList $fields |
||
98 | */ |
||
99 | 1 | public function updateSettingsFields(\FieldList $fields) |
|
107 | } |
||
108 |