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() ) |
||
52 | |||
53 | /** |
||
54 | * The default model to use when none is provided to the constructor. |
||
55 | * This method should be overriden by child class to define the default |
||
56 | * model. |
||
57 | * |
||
58 | * @return array |
||
59 | */ |
||
60 | public function default_model() |
||
64 | |||
65 | /** |
||
66 | * The list of required model arguments. |
||
67 | * This method should be overriden by child class to specify required model |
||
68 | * arguments. |
||
69 | * |
||
70 | * @return array |
||
71 | */ |
||
72 | public function required_arguments() |
||
76 | |||
77 | /** |
||
78 | * Set the model data for this component. |
||
79 | * |
||
80 | * @return array |
||
81 | */ |
||
82 | public function set_model( $model ) |
||
101 | |||
102 | /** |
||
103 | * Get the name for this component by parsing the name template. |
||
104 | * |
||
105 | * @return string |
||
106 | */ |
||
107 | public function get_name() |
||
111 | |||
112 | /** |
||
113 | * Add an HTML class to the list of HTML classes to be printed when the |
||
114 | * component is rendered. |
||
115 | * |
||
116 | * @param string $class |
||
117 | */ |
||
118 | public function add_html_class( $class ) |
||
125 | |||
126 | /** |
||
127 | * Remove an HTML class to the list of HTML classes to be printed when the |
||
128 | * component is rendered. |
||
129 | * |
||
130 | * @param string $class |
||
131 | */ |
||
132 | public function remove_html_class( $class ) |
||
145 | |||
146 | /** |
||
147 | * Set the validity of this component if it supports validation. |
||
148 | * |
||
149 | * @param type $validity |
||
150 | */ |
||
151 | Public function set_validity( $validity ) |
||
159 | |||
160 | /** |
||
161 | * Generate common UI component wrapper attributes |
||
162 | */ |
||
163 | public function component_attributes() |
||
171 | |||
172 | /** |
||
173 | * Enqueue component's script and render it. |
||
174 | * |
||
175 | * {@inheritdoc} |
||
176 | */ |
||
177 | public function render( $echo = false ) |
||
191 | |||
192 | /** |
||
193 | * Enqueue styles/scripts required for this element. |
||
194 | */ |
||
195 | public function enqueue_scripts() |
||
200 | |||
201 | /** |
||
202 | * A hook that is called once the component has been created. |
||
203 | */ |
||
204 | protected function on_created() {} |
||
205 | } |