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 | public $html_classes = array(); |
||
30 | |||
31 | /** |
||
32 | * Constructor |
||
33 | * |
||
34 | * @param array $model |
||
35 | */ |
||
36 | public function __construct( array $model = array() ) |
||
47 | |||
48 | /** |
||
49 | * The default model to use when none is provided to the constructor. |
||
50 | * This method should be overriden by child class to define the default |
||
51 | * model. |
||
52 | * |
||
53 | * @return array |
||
54 | */ |
||
55 | public function default_model() |
||
59 | |||
60 | /** |
||
61 | * The list of required model arguments. |
||
62 | * This method should be overriden by child class to specify required model |
||
63 | * arguments. |
||
64 | * |
||
65 | * @return array |
||
66 | */ |
||
67 | public function required_arguments() |
||
71 | |||
72 | /** |
||
73 | * Set the model data for this component. |
||
74 | * |
||
75 | * @return array |
||
76 | */ |
||
77 | public function set_model( $model ) |
||
96 | |||
97 | /** |
||
98 | * Get the name for this component by parsing the name template. |
||
99 | * |
||
100 | * @return string |
||
101 | */ |
||
102 | public function get_name() |
||
106 | |||
107 | /** |
||
108 | * Add an HTML class to the list of HTML classes to be printed when the |
||
109 | * component is rendered. |
||
110 | * |
||
111 | * @param string $class |
||
112 | */ |
||
113 | public function add_html_class( $class ) |
||
120 | |||
121 | /** |
||
122 | * Remove an HTML class to the list of HTML classes to be printed when the |
||
123 | * component is rendered. |
||
124 | * |
||
125 | * @param string $class |
||
126 | */ |
||
127 | public function remove_html_class( $class ) |
||
140 | |||
141 | /** |
||
142 | * Set the validity of this component if it supports validation. |
||
143 | * |
||
144 | * @param type $validity |
||
145 | */ |
||
146 | Public function set_validity( $validity ) |
||
154 | |||
155 | /** |
||
156 | * Generate common UI component wrapper attributes |
||
157 | */ |
||
158 | public function component_attributes() |
||
166 | |||
167 | /** |
||
168 | * Enqueue component's script and render it. |
||
169 | * |
||
170 | * {@inheritdoc} |
||
171 | */ |
||
172 | public function render( $echo = false ) |
||
177 | |||
178 | /** |
||
179 | * Enqueue styles/scripts required for this element. |
||
180 | */ |
||
181 | public function enqueue_scripts() |
||
186 | |||
187 | /** |
||
188 | * A hook that is called once the component has been created. |
||
189 | */ |
||
190 | protected function on_created() {} |
||
191 | } |