1 | <?php |
||
5 | abstract class Customization |
||
6 | { |
||
7 | /** |
||
8 | * Actual customization data. |
||
9 | * |
||
10 | * @var array |
||
11 | */ |
||
12 | protected $data = []; |
||
13 | |||
14 | /** |
||
15 | * Customization-related settings. |
||
16 | * |
||
17 | * @var SettingsManager |
||
18 | */ |
||
19 | protected $settings; |
||
20 | |||
21 | /** |
||
22 | * List of disabled common editables names. |
||
23 | * |
||
24 | * @var array |
||
25 | */ |
||
26 | protected $disabledEditables = []; |
||
27 | |||
28 | /** |
||
29 | * Creates groupped editables list. |
||
30 | * |
||
31 | * @return array |
||
32 | */ |
||
33 | abstract public function editables(); |
||
34 | |||
35 | /** |
||
36 | * Builds template data. |
||
37 | * |
||
38 | * @return mixed |
||
39 | */ |
||
40 | abstract public function build(); |
||
41 | |||
42 | /** |
||
43 | * Returns ['customization_name' => 'setting_key'] map. |
||
44 | * |
||
45 | * @return array |
||
46 | */ |
||
47 | public function settingsMap() |
||
53 | |||
54 | /** |
||
55 | * Triggers before the save settings operation. |
||
56 | */ |
||
57 | public function beforeSaving() |
||
61 | |||
62 | /** |
||
63 | * Saves customization settings. |
||
64 | * |
||
65 | * @return $this |
||
66 | */ |
||
67 | public function save() |
||
75 | |||
76 | /** |
||
77 | * Returns value for given customization data key or default value. |
||
78 | * |
||
79 | * @param string $key |
||
80 | * @param mixed $defaultValue = null |
||
81 | * |
||
82 | * @return mixed |
||
83 | */ |
||
84 | public function get(string $key, $defaultValue = null) |
||
88 | |||
89 | /** |
||
90 | * Returns customization data. |
||
91 | * |
||
92 | * @return array |
||
93 | */ |
||
94 | public function all() |
||
98 | |||
99 | /** |
||
100 | * Sets preview data. |
||
101 | * |
||
102 | * @param array $previewData |
||
103 | * |
||
104 | * @return $this |
||
105 | */ |
||
106 | public function setPreviewData(array $previewData = []) |
||
122 | |||
123 | /** |
||
124 | * Sets settings manager. |
||
125 | * |
||
126 | * @param SettingsManager $settings |
||
127 | * |
||
128 | * @return $this |
||
129 | */ |
||
130 | public function setSettings(SettingsManager $settings) |
||
136 | |||
137 | /** |
||
138 | * @param array|string $editables |
||
139 | * |
||
140 | * @return $this |
||
141 | */ |
||
142 | public function disableEditables($editables) |
||
154 | |||
155 | /** |
||
156 | * @return array |
||
157 | */ |
||
158 | public function getDisabledEditables() |
||
162 | |||
163 | /** |
||
164 | * Renames customization keys to settings keys. |
||
165 | * |
||
166 | * @param array $previewData |
||
167 | * @param array $map |
||
168 | * |
||
169 | * @return array |
||
170 | */ |
||
171 | protected function renamePreviewDataKeys(array $previewData, array $map) |
||
186 | |||
187 | /** |
||
188 | * Returns value from preview data or default value. |
||
189 | * |
||
190 | * @param string $key |
||
191 | * @param null $defaultValue |
||
192 | * |
||
193 | * @return mixed|null |
||
194 | */ |
||
195 | protected function setting(string $key, $defaultValue = null) |
||
199 | |||
200 | /** |
||
201 | * Returns value from preview data or default value with replaced placeholders. |
||
202 | * |
||
203 | * @param string $key |
||
204 | * @param array $placeholders |
||
205 | * @param null $defaultValue |
||
206 | * |
||
207 | * @return string |
||
208 | */ |
||
209 | protected function settingWithPlaceholders(string $key, array $placeholders = [], $defaultValue = null) |
||
215 | |||
216 | /** |
||
217 | * Creates new editables group. |
||
218 | * |
||
219 | * @param string $id |
||
220 | * @param string $title |
||
221 | * @param \Closure $settingsFactory |
||
222 | * |
||
223 | * @return array |
||
224 | */ |
||
225 | protected function group(string $id, string $title, \Closure $settingsFactory) |
||
233 | |||
234 | /** |
||
235 | * Creates new Editable. |
||
236 | * |
||
237 | * @param string $name |
||
238 | * @param string $type |
||
239 | * @param string|null $title |
||
240 | * @param null $value |
||
241 | * @param array $attributes |
||
242 | * |
||
243 | * @return Editable |
||
244 | */ |
||
245 | protected function editable(string $name, string $type, string $title = null, $value = null, array $attributes = []) |
||
253 | } |
||
254 |