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 ) |
||
106 | |||
107 | /** |
||
108 | * Get the name for this component by parsing the name template. |
||
109 | * |
||
110 | * @return string |
||
111 | */ |
||
112 | public function get_name() |
||
116 | |||
117 | /** |
||
118 | * Add an HTML class to the list of HTML classes to be printed when the |
||
119 | * component is rendered. |
||
120 | * |
||
121 | * @param string $class |
||
122 | */ |
||
123 | public function add_html_class( $class ) |
||
130 | |||
131 | /** |
||
132 | * Remove an HTML class to the list of HTML classes to be printed when the |
||
133 | * component is rendered. |
||
134 | * |
||
135 | * @param string $class |
||
136 | */ |
||
137 | public function remove_html_class( $class ) |
||
150 | |||
151 | /** |
||
152 | * Set the validity of this component if it supports validation. |
||
153 | * |
||
154 | * @param type $validity |
||
155 | */ |
||
156 | Public function set_validity( $validity ) |
||
164 | |||
165 | /** |
||
166 | * Generate common UI component wrapper attributes |
||
167 | */ |
||
168 | public function component_attributes() |
||
176 | |||
177 | /** |
||
178 | * Enqueue component's script and render it. |
||
179 | * |
||
180 | * {@inheritdoc} |
||
181 | */ |
||
182 | public function render( $echo = false ) |
||
196 | |||
197 | /** |
||
198 | * Enqueue styles/scripts required for this element. |
||
199 | */ |
||
200 | public function enqueue_scripts() |
||
205 | |||
206 | /** |
||
207 | * A hook that is called once the component has been created. |
||
208 | */ |
||
209 | protected function on_created() {} |
||
210 | } |