-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomponents.api.php
More file actions
394 lines (366 loc) · 10.6 KB
/
components.api.php
File metadata and controls
394 lines (366 loc) · 10.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
<?php
/**
* @file
* This file contains no working PHP code; it exists to provide additional
* documentation for doxygen as well as to document hooks in the standard
* Drupal manner.
*/
/**
* @addtogroup hooks
* @{
*/
/***********************/
/* COMPONENT functions */
/***********************/
/**
* Acts o component being loaded from the database.
*
* This hook is invoked during component loading, which is handled by
* entity_load(), via the EntityCRUDController.
*
* @param $entities
* An array of component entities being loaded, keyed by id.
*
* @see hook_entity_load()
*/
function hook_component_load($entities) {
$result = db_query('SELECT pid, foo FROM {mytable} WHERE pid IN(:ids)', array(':ids' => array_keys($entities)));
foreach ($result as $record) {
$entities[$record->pid]->foo = $record->foo;
}
}
/**
* Responds when a component is inserted.
*
* This hook is invoked after the component is inserted into the database.
*
* @param $component
* The component that is being inserted.
*
* @see hook_entity_insert()
*/
function hook_component_insert($component) {
db_insert('mytable')
->fields(array(
'pid' => $component->pid,
'extra' => $component->extra,
))
->execute();
}
/**
* Acts on a component being inserted or updated.
*
* This hook is invoked before the component is saved to the database.
*
* @param $component
* The component that is being inserted or updated.
*
* @see hook_entity_presave()
*/
function hook_component_presave($component) {
$component->extra = 'foo';
}
/**
* Responds to a component being componented.
*
* This hook is invoked after the component has been updated in the database.
*
* @param $component
* The component that is being updated.
*
* @see hook_entity_update()
*/
function hook_component_update($component) {
db_update('mytable')
->fields(array('extra' => $component->extra))
->condition('pid', $component->pid)
->execute();
}
/**
* Responds to component deletion.
*
* This hook is invoked after the component has been removed from the database.
*
* @param $component
* The component that is being deleted.
*
* @see hook_entity_delete()
*/
function hook_component_delete($component) {
db_delete('mytable')
->condition('pid', $component->pid)
->execute();
}
/**
* Act on a component that is being assembled before rendering.
*
* @param $component
* The component entity.
* @param $view_mode
* The view mode the component is rendered in.
* @param $langcode
* The language code used for rendering.
*
* The module may add elements to $component->content prior to rendering. The
* structure of $component->content is a renderable array as expected by
* drupal_render().
*
* @see hook_entity_prepare_view()
* @see hook_entity_view()
*/
function hook_component_view($component, $view_mode, $langcode) {
$component->content['my_additional_field'] = array(
'#markup' => $additional_field,
'#weight' => 10,
'#theme' => 'mymodule_my_additional_field',
);
}
/**
* Alter the results of entity_view() for components.
*
* @param $build
* A renderable array representing the component content.
*
* This hook is called after the content has been assembled in a structured
* array and may be used for doing processing which requires that the complete
* component content structure has been built.
*
* If the module wishes to act on the rendered HTML of the component rather than
* the structured content array, it may use this hook to add a #post_render
* callback. Alternatively, it could also implement hook_preprocess_component().
* See drupal_render() and theme() documentation respectively for details.
*
* @see hook_entity_view_alter()
*/
function hook_component_view_alter($build) {
if ($build['#view_mode'] == 'full' && isset($build['an_additional_field'])) {
// Change its weight.
$build['an_additional_field']['#weight'] = -10;
// Add a #post_render callback to act on the rendered HTML of the entity.
$build['#post_render'][] = 'my_module_post_render';
}
}
/**
* Define default component configurations.
*
* @return
* An array of default components, keyed by component names.
*
* @see hook_default_component_alter()
*/
/*function hook_default_component() {
$defaults['main'] = entity_create('component', array(
'label' => t('Entity example'),
'weight' => 0,
));
return $defaults;
}*/
/**
* Alter default component configurations.
*
* @param $defaults
* An array of default components, keyed by component names.
*
* @see hook_default_component()
*/
/*function hook_default_component_alter(&$defaults) {
$defaults['main']->label = 'custom label';
}*/
/**
* Alter component forms.
*
* Modules may alter the component entity form by making use of this hook or
* the entity bundle specific hook_form_component_edit_BUNDLE_form_alter().
* #entity_builders may be used in order to copy the values of added form
* elements to the entity, just as documented for
* entity_form_submit_build_entity().
*
* @param $form
* Nested array of form elements that comprise the form.
* @param $form_state
* A keyed array containing the current state of the form.
*/
/*function hook_form_component_form_alter(&$form, &$form_state) {
// Your alterations.
}*/
/****************************/
/* COMPONENT_TYPE functions */
/****************************/
/**
* Acts on component type being loaded from the database.
*
* This hook is invoked during component type loading, which is handled by
* entity_load(), via the EntityCRUDController.
*
* @param $entities
* An array of component type entities being loaded, keyed by id.
*
* @see hook_entity_load()
*/
function hook_component_type_load($entities) {
/*$result = db_query('SELECT pid, foo FROM {mytable} WHERE pid IN(:ids)', array(':ids' => array_keys($entities)));
foreach ($result as $record) {
$entities[$record->pid]->foo = $record->foo;
}*/
if (isset($types['main'])) {
}
}
/**
* Responds when a component type is inserted.
*
* This hook is invoked after the component type is inserted into the database.
*
* @param $component_type
* The component type that is being inserted.
*
* @see hook_entity_insert()
*/
function hook_component_type_insert($component_type) {
db_insert('mytable')
->fields(array(
'pid' => $component_type->pid,
'extra' => $component_type->extra,
))
->execute();
}
/**
* Acts on a component type being inserted or updated.
*
* This hook is invoked before the component type is saved to the database.
*
* @param $component_type
* The component type that is being inserted or updated.
*
* @see hook_entity_presave()
*/
function hook_component_type_presave($component_type) {
$component_type->extra = 'foo';
}
/**
* Responds to a component type being updated.
*
* This hook is invoked after the component type has been updated in the database.
*
* @param $component_type
* The component type that is being updated.
*
* @see hook_entity_update()
*/
function hook_component_type_update($component_type) {
db_update('mytable')
->fields(array('extra' => $component_type->extra))
->condition('pid', $component_type->pid)
->execute();
}
/**
* Responds to component type deletion.
*
* This hook is invoked after the component type has been removed from the database.
*
* @param $component_type
* The component type that is being deleted.
*
* @see hook_entity_delete()
*/
function hook_component_type_delete($component_type) {
db_delete('mytable')
->condition('pid', $component_type->pid)
->execute();
}
/**
* Act on a component type that is being assembled before rendering.
*
* @param $component_type
* The component type entity.
* @param $view_mode
* The view mode the component type is rendered in.
* @param $langcode
* The language code used for rendering.
*
* The module may add elements to $component_type->content prior to rendering. The
* structure of $component_type->content is a renderable array as expected by
* drupal_render().
*
* @see hook_entity_prepare_view()
* @see hook_entity_view()
*/
/*function hook_component_type_view($component_type, $view_mode, $langcode) {
$component_type->content['my_additional_field'] = array(
'#markup' => $additional_field,
'#weight' => 10,
'#theme' => 'mymodule_my_additional_field',
);
}*/
/**
* Alter the results of entity_view() for component types.
*
* @param $build
* A renderable array representing the component type content.
*
* This hook is called after the content has been assembled in a structured
* array and may be used for doing processing which requires that the complete
* component type content structure has been built.
*
* If the module wishes to act on the rendered HTML of the component type rather than
* the structured content array, it may use this hook to add a #post_render
* callback. Alternatively, it could also implement hook_preprocess_component_type().
* See drupal_render() and theme() documentation respectively for details.
*
* @see hook_entity_view_alter()
*/
/*function hook_component_type_view_alter($build) {
if ($build['#view_mode'] == 'full' && isset($build['an_additional_field'])) {
// Change its weight.
$build['an_additional_field']['#weight'] = -10;
// Add a #post_render callback to act on the rendered HTML of the entity.
$build['#post_render'][] = 'my_module_post_render';
}
}*/
/**
* Define default component type configurations.
*
* @return
* An array of default component types, keyed by component type names.
*
* @see hook_default_component_type_alter()
*/
function hook_default_component_type() {
$types['main'] = new ComponentType(array(
'type' => 'main',
'label' => t('Component'),
'weight' => 0,
'locked' => TRUE,
));
return $types;
}
/**
* Alter default component type configurations.
*
* @param $defaults
* An array of default component types, keyed by component type names.
*
* @see hook_default_component_type()
*/
function hook_default_component_type_alter(&$defaults) {
$defaults['main']->label = 'custom label';
}
/**
* Alter component type forms.
*
* Modules may alter the component type entity form by making use of this hook or
* the entity bundle specific hook_form_component_type_edit_BUNDLE_form_alter().
* #entity_builders may be used in order to copy the values of added form
* elements to the entity, just as documented for
* entity_form_submit_build_entity().
*
* @param $form
* Nested array of form elements that comprise the form.
* @param $form_state
* A keyed array containing the current state of the form.
*/
function hook_form_component_type_form_alter(&$form, &$form_state) {
// Your alterations.
}
/**
* @}
*/