You are here

class EntityMenuLinkController in Entity menu links 7

Controller class for menu links.

This extends the DrupalDefaultEntityController class, adding required special handling for menu link objects.

Hierarchy

Expanded class hierarchy of EntityMenuLinkController

1 string reference to 'EntityMenuLinkController'
entity_menu_links_entity_info in ./entity_menu_links.module
Implements hook_entity_info().

File

./entity_menu_links.controller.inc, line 8

View source
class EntityMenuLinkController extends EntityAPIController {
  protected function buildQuery($ids, $conditions = array(), $revision_id = FALSE) {
    $query = parent::buildQuery($ids, $conditions, $revision_id);

    // Specify additional fields from the menu tables.
    $query
      ->leftJoin('menu_router', 'm', 'base.router_path = m.path');
    $query
      ->fields('m', array_diff(drupal_schema_fields_sql('menu_router'), array(
      'weight',
    )));
    return $query;
  }
  protected function attachLoad(&$menu_links, $revision_id = FALSE) {
    foreach ($menu_links as $mlid => &$item) {
      $item = (array) $item;
      $item['options'] = unserialize($item['options']);
      if ($item['external']) {
        $item['access'] = TRUE;
        $map = array();
        $item['href'] = $item['link_path'];
        $item['title'] = $item['link_title'];
        $item['localized_options'] = $item['options'];
      }
      else {
        $map = explode('/', $item['link_path']);
        if (!empty($item['to_arg_functions'])) {
          _menu_link_map_translate($map, $item['to_arg_functions']);
        }
        $item['href'] = implode('/', $map);

        // Note - skip callbacks without real values for their arguments.
        if (strpos($item['href'], '%') !== FALSE) {
          $item['access'] = FALSE;
        }

        // menu_tree_check_access() may set this ahead of time for links to nodes.
        if (!isset($item['access'])) {
          if (!empty($item['load_functions']) && !_menu_load_objects($item, $map)) {

            // An error occurred loading an object.
            $item['access'] = FALSE;
            $item = (object) $item;
            continue;
          }
          _menu_check_access($item, $map);
        }

        // For performance, don't localize a link the user can't access.
        if ($item['access']) {
          _menu_item_localize($item, $map, TRUE);
        }
      }

      // Allow other customizations - e.g. adding a page-specific query string to the
      // options array. For performance reasons we only invoke this hook if the link
      // has the 'alter' flag set in the options array.
      if (!empty($item['options']['alter'])) {
        drupal_alter('translated_menu_link', $item, $map);
      }
      $item = (object) $item;
    }
    parent::attachLoad($menu_links, $revision_id);
  }

  /**
   * Overrides delete from EntityAPIController
   */
  public function delete($ids, DatabaseTransaction $transaction = NULL) {
    foreach ($ids as $mlid) {
      menu_link_delete($mlid);
    }
  }

  /**
   * Overrides save from EntityAPIController
   */
  public function save($entity, DatabaseTransaction $transaction = NULL) {
    $menu_link = (array) $entity;
    $mlid = menu_link_save($menu_link);
    if (FALSE === $mlid) {
      $transaction
        ->rollback();
      throw new Exception('Could not save menu_link');
    }
    $entity->mlid = $mlid;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DrupalDefaultEntityController::$cache protected property Whether this entity type should use the static cache.
DrupalDefaultEntityController::$entityCache protected property Static cache of entities, keyed by entity ID.
DrupalDefaultEntityController::$entityInfo protected property Array of information about the entity.
DrupalDefaultEntityController::$entityType protected property Entity type for this controller instance.
DrupalDefaultEntityController::$hookLoadArguments protected property Additional arguments to pass to hook_TYPE_load().
DrupalDefaultEntityController::$idKey protected property Name of the entity's ID field in the entity database table.
DrupalDefaultEntityController::$revisionKey protected property Name of entity's revision database table field, if it supports revisions.
DrupalDefaultEntityController::$revisionTable protected property The table that stores revisions, if the entity supports revisions.
DrupalDefaultEntityController::cacheGet protected function Gets entities from the static cache. 1
DrupalDefaultEntityController::cacheSet protected function Stores entities in the static entity cache.
DrupalDefaultEntityController::cleanIds protected function Ensures integer entity IDs are valid.
DrupalDefaultEntityController::filterId protected function Callback for array_filter that removes non-integer IDs.
EntityAPIController::$bundleKey protected property
EntityAPIController::$cacheComplete protected property
EntityAPIController::$defaultRevisionKey protected property
EntityAPIController::buildContent public function Implements EntityAPIControllerInterface. Overrides EntityAPIControllerInterface::buildContent
EntityAPIController::create public function Implements EntityAPIControllerInterface. Overrides EntityAPIControllerInterface::create
EntityAPIController::deleteRevision public function Implements EntityAPIControllerRevisionableInterface::deleteRevision(). Overrides EntityAPIControllerRevisionableInterface::deleteRevision
EntityAPIController::export public function Implements EntityAPIControllerInterface. Overrides EntityAPIControllerInterface::export 1
EntityAPIController::import public function Implements EntityAPIControllerInterface. Overrides EntityAPIControllerInterface::import
EntityAPIController::invoke public function Implements EntityAPIControllerInterface. Overrides EntityAPIControllerInterface::invoke 1
EntityAPIController::load public function Overridden. Overrides DrupalDefaultEntityController::load 1
EntityAPIController::query public function Builds and executes the query for loading.
EntityAPIController::renderEntityProperty protected function Renders a single entity property.
EntityAPIController::resetCache public function Overrides DrupalDefaultEntityController::resetCache(). Overrides DrupalDefaultEntityController::resetCache 1
EntityAPIController::saveRevision protected function Saves an entity revision.
EntityAPIController::view public function Implements EntityAPIControllerInterface. Overrides EntityAPIControllerInterface::view 1
EntityAPIController::__construct public function Overridden. Overrides DrupalDefaultEntityController::__construct 1
EntityMenuLinkController::attachLoad protected function Attaches data to entities upon loading. Overrides DrupalDefaultEntityController::attachLoad
EntityMenuLinkController::buildQuery protected function Overrides DrupalDefaultEntityController::buildQuery(). Overrides EntityAPIController::buildQuery
EntityMenuLinkController::delete public function Overrides delete from EntityAPIController Overrides EntityAPIController::delete
EntityMenuLinkController::save public function Overrides save from EntityAPIController Overrides EntityAPIController::save