Projet

Général

Profil

Paste
Télécharger (1,01 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / menu_token / plugins / menu_token_entity_context.inc @ 27370441

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
    $path_components = explode('/', $entity_info['path']);
25
    foreach ($path_components as $position => $component) {
26
      // If this is a menu argument, then use the current position to find
27
      // the entity id.
28
      if (strpos($component, '%') === 0) {
29
        break;
30
      }
31

    
32
      // If the current URL deviates from the expected path, assume the
33
      // entity is not present.
34
      if ($component !== arg($position)) {
35
        return FALSE;
36
      }
37
    }
38

    
39
    return entity_load_single($entity_type, arg($position));
40
  }
41
}