1 |
85ad3d82
|
Assos Assos
|
<?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 |
ca92d645
|
Assos Assos
|
// As the $entity object is not available in $options, we can't use uri_callback method.
|
25 |
|
|
// Thus directly look for path in the entity info.
|
26 |
|
|
if (isset($entity_info['path'])) {
|
27 |
|
|
$path = $entity_info['path'];
|
28 |
|
|
}
|
29 |
|
|
// Or look for a default path.
|
30 |
|
|
elseif (isset($entity_info['default path'])) {
|
31 |
|
|
$path = $entity_info['default path'];
|
32 |
|
|
}
|
33 |
|
|
// No path available so far, so exit with NULL.
|
34 |
|
|
else {
|
35 |
|
|
return NULL;
|
36 |
|
|
}
|
37 |
|
|
|
38 |
|
|
$path_components = explode('/', $path);
|
39 |
7e072189
|
Assos Assos
|
foreach ($path_components as $position => $component) {
|
40 |
|
|
// If this is a menu argument, then use the current position to find
|
41 |
|
|
// the entity id.
|
42 |
|
|
if (strpos($component, '%') === 0) {
|
43 |
|
|
break;
|
44 |
|
|
}
|
45 |
|
|
|
46 |
|
|
// If the current URL deviates from the expected path, assume the
|
47 |
|
|
// entity is not present.
|
48 |
|
|
if ($component !== arg($position)) {
|
49 |
|
|
return FALSE;
|
50 |
|
|
}
|
51 |
85ad3d82
|
Assos Assos
|
}
|
52 |
|
|
|
53 |
7e072189
|
Assos Assos
|
return entity_load_single($entity_type, arg($position));
|
54 |
85ad3d82
|
Assos Assos
|
}
|
55 |
|
|
} |