You are here

class menu_token_entity_context in Menu Token 7

Hierarchy

Expanded class hierarchy of menu_token_entity_context

1 string reference to 'menu_token_entity_context'
menu_token_menu_token_plugins in ./menu_token.module
Implements hook_menu_token_plugins().

File

plugins/menu_token_entity_context.inc, line 3

View source
class menu_token_entity_context extends menu_token_handler {
  public function form_options($options) {

    // Nothing to do here.
  }
  public function form_submit($form, &$form_state) {

    // Nothing to do here.
  }
  public function form_alter(&$form, &$form_state) {

    // Nothing to do here.
  }
  public function object_load($options) {
    $entity_type = $options['_type'];
    $entity_info = entity_get_info($entity_type);
    $original_map = arg();
    $parts = array_slice($original_map, 0, MENU_MAX_PARTS);
    $ancestors = menu_get_ancestors($parts);
    $router_item = db_query_range('SELECT * FROM {menu_router} WHERE path IN (:ancestors) ORDER BY fit DESC', 0, 1, array(
      ':ancestors' => $ancestors,
    ))
      ->fetchAssoc();

    // Check for views argument.
    // Warning: only returns the first entity even if there are multiple arguments
    // of the same entity type in the url. The module as is doesn't allow for
    // argument selection.
    if ($router_item['page_callback'] == 'views_page' && module_exists('views')) {
      $view = views_get_page_view();
      $entity_key = $entity_info['entity keys']['id'];
      if (isset($view->argument) && array_key_exists($entity_key, $view->argument)) {
        return entity_load_single($entity_type, $view->argument[$entity_key]->argument);
      }
    }

    // Check for load function.
    // Warning: only returns the first entity even if there are multiple load
    // functions of the same type. The module as is doesn't allow for argument
    // selection.
    if (!empty($entity_info['load hook']) && !empty($router_item['load_functions'])) {
      $load_functions = unserialize($router_item['load_functions']);
      if ($key = array_search($entity_info['load hook'], $load_functions)) {
        return entity_load_single($entity_type, $parts[$key]);
      }
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
menu_token_entity_context::form_alter public function You can alter the menu item administration form with this function. Overrides menu_token_handler::form_alter
menu_token_entity_context::form_options public function You can provide options for your menu token handler via this function. The return value will be appended to the form as soon as the administrator chooses your plugin. Overrides menu_token_handler::form_options
menu_token_entity_context::form_submit public function This function allows your plugin to act upon form submission. The return value will be added to the $options array and thus should be an array itself. Overrides menu_token_handler::form_submit
menu_token_entity_context::object_load public function This function is used to load the relevant token replacement object. Overrides menu_token_handler::object_load
menu_token_handler::form_validate public function This function allows your plugin to act upon form validation. The return value will be added to the $options array and thus should be an array itself. 2