1 | <?php |
||
8 | abstract class AbstractComponent |
||
9 | extends Template |
||
|
|||
10 | { |
||
11 | /** |
||
12 | * This template is used to generate the name for this component. the token |
||
13 | * {{name}} will be replaced by the component's name during runtime. |
||
14 | * |
||
15 | * @var string |
||
16 | */ |
||
17 | public $name_template = '{{name}}'; |
||
18 | |||
19 | /** |
||
20 | * This template is used to generate the name for this component when it is |
||
21 | * used as a child component in a composite component. The token |
||
22 | * {{parent_name}} will be replaced with the name of the parent (composite) |
||
23 | * component. |
||
24 | * |
||
25 | * @var string |
||
26 | */ |
||
27 | public $composite_name_template = '{{parent_name}}[{{name}}]'; |
||
28 | |||
29 | /** |
||
30 | * A list of HTML classes to be added to the wrapper div of this component. |
||
31 | * |
||
32 | * @var array |
||
33 | */ |
||
34 | public $html_classes = array(); |
||
35 | |||
36 | /** |
||
37 | * Constructor |
||
38 | * |
||
39 | * @param array $model |
||
40 | */ |
||
41 | public function __construct( array $model = array() ) |
||
57 | |||
58 | /** |
||
59 | * The default model to use when none is provided to the constructor. |
||
60 | * This method should be overriden by child class to define the default |
||
61 | * model. |
||
62 | * |
||
63 | * @return array |
||
64 | */ |
||
65 | public function default_model() |
||
69 | |||
70 | /** |
||
71 | * The list of required model arguments. |
||
72 | * This method should be overriden by child class to specify required model |
||
73 | * arguments. |
||
74 | * |
||
75 | * @return array |
||
76 | */ |
||
77 | public function required_arguments() |
||
81 | |||
82 | /** |
||
83 | * Set the model data for this component. |
||
84 | * |
||
85 | * @return array |
||
86 | */ |
||
87 | public function set_model( $model ) |
||
112 | |||
113 | /** |
||
114 | * Get the name for this component by parsing the name template. |
||
115 | * |
||
116 | * @return string |
||
117 | */ |
||
118 | public function get_name() |
||
122 | |||
123 | /** |
||
124 | * Add an HTML class to the list of HTML classes to be printed when the |
||
125 | * component is rendered. |
||
126 | * |
||
127 | * @param string $class |
||
128 | */ |
||
129 | public function add_html_class( $class ) |
||
136 | |||
137 | /** |
||
138 | * Remove an HTML class to the list of HTML classes to be printed when the |
||
139 | * component is rendered. |
||
140 | * |
||
141 | * @param string $class |
||
142 | */ |
||
143 | public function remove_html_class( $class ) |
||
156 | |||
157 | /** |
||
158 | * Set the validity of this component if it supports validation. |
||
159 | * |
||
160 | * @param type $validity |
||
161 | */ |
||
162 | Public function set_validity( $validity ) |
||
170 | |||
171 | /** |
||
172 | * Generate common UI component wrapper attributes |
||
173 | */ |
||
174 | public function component_attributes() |
||
182 | |||
183 | /** |
||
184 | * Enqueue component's script and render it. |
||
185 | * |
||
186 | * {@inheritdoc} |
||
187 | */ |
||
188 | public function render( $echo = false ) |
||
202 | |||
203 | /** |
||
204 | * Enqueue styles/scripts required for this element. |
||
205 | */ |
||
206 | public function enqueue_scripts() |
||
211 | |||
212 | /** |
||
213 | * A hook that is called once the component has been created. |
||
214 | */ |
||
215 | protected function on_created() {} |
||
216 | } |