1
|
<?php
|
2
|
|
3
|
class menu_token_entity_context implements menu_token_handler {
|
4
|
function form_options($options) {
|
5
|
// Nothing to do here.
|
6
|
}
|
7
|
|
8
|
function form_submit($form, &$form_state) {
|
9
|
// Nothing to do here.
|
10
|
}
|
11
|
|
12
|
function form_validate($form, &$form_state) {
|
13
|
// Nothing to do here.
|
14
|
}
|
15
|
|
16
|
function form_alter(&$form, &$form_state) {
|
17
|
// Nothing to do here.
|
18
|
}
|
19
|
|
20
|
function object_load($options) {
|
21
|
$entity_type = $options['_type'];
|
22
|
$entity_info = entity_get_info($entity_type);
|
23
|
|
24
|
// Taken from entity_uri() to determine the uri callback for this entity
|
25
|
// type.
|
26
|
// A bundle-specific callback takes precedence over the generic one for the
|
27
|
// entity type.
|
28
|
if (isset($entity_info['uri callback'])) {
|
29
|
$uri_callback = $entity_info['uri callback'];
|
30
|
}
|
31
|
else {
|
32
|
return NULL;
|
33
|
}
|
34
|
|
35
|
$path = @$uri_callback();
|
36
|
$path = current(explode('/', $path['path']));
|
37
|
|
38
|
if (arg(0) === $path && is_numeric(arg(1))) {
|
39
|
return entity_load_single($entity_type, arg(1));
|
40
|
}
|
41
|
|
42
|
return FALSE;
|
43
|
}
|
44
|
}
|