1
|
<?php
|
2
|
|
3
|
class menu_token_entity_user_defined implements menu_token_handler {
|
4
|
function form_options($options) {
|
5
|
$output['menu_token_entity_user_defined'] = array(
|
6
|
'#title' => t('Entity ID'),
|
7
|
'#description' => t('The id of the entity that this token handler should load.'),
|
8
|
'#type' => 'textfield',
|
9
|
'#default_value' => isset($options['id']) ? $options['id'] : '',
|
10
|
);
|
11
|
|
12
|
return $output;
|
13
|
}
|
14
|
|
15
|
function form_submit($form, &$form_state) {
|
16
|
$options['id'] = $form_state['values']['menu_token_entity_user_defined'];
|
17
|
return $options;
|
18
|
}
|
19
|
|
20
|
function form_validate($form, &$form_state) {
|
21
|
$id = $form_state['values']['menu_token_entity_user_defined'];
|
22
|
$entity_type = $form_state['_menu_token_entity_type'];
|
23
|
|
24
|
if (!is_numeric($id)) {
|
25
|
form_set_error('menu_token_entity_user_defined', t('Entity ID should be numeric.'));
|
26
|
return;
|
27
|
}
|
28
|
else if (!entity_load_single($entity_type, $id)) {
|
29
|
form_set_error('menu_token_entity_user_defined', t('Entity should exist.'));
|
30
|
return;
|
31
|
}
|
32
|
}
|
33
|
|
34
|
function form_alter(&$form, &$form_state) {
|
35
|
// Nothing to do here.
|
36
|
}
|
37
|
|
38
|
function object_load($options) {
|
39
|
$entity_type = $options['_type'];
|
40
|
|
41
|
if (is_numeric($options['id'])) {
|
42
|
return entity_load_single($entity_type, $options['id']);
|
43
|
}
|
44
|
|
45
|
return FALSE;
|
46
|
}
|
47
|
}
|