You are here

public function AckMenuMap::realmLinks in Access Control Kit 7

Implements AckMenuHandlerInterface::realmLinks().

Overrides AckMenuHandlerInterface::realmLinks

1 call to AckMenuMap::realmLinks()
AckMenuMap::objectFormAlter in ack_menu/handlers/ack_menu_map.inc
Overrides AccessControlKitHandler::objectFormAlter().

File

ack_menu/handlers/ack_menu_map.inc, line 252
Contains the handler class for mapping menu links to access realms.

Class

AckMenuMap
Controls access to menu links based on realm mapping.

Code

public function realmLinks($realm, $menu_name) {
  $mapped_links = $this
    ->mappedLinks($realm);
  if (!empty($mapped_links) && !empty($this->menus) && in_array($menu_name, $this->menus)) {

    // This is similar to menu_overview_form() and _menu_build_tree().
    $query = db_select('menu_links', 'ml', array(
      'fetch' => PDO::FETCH_ASSOC,
    ));
    $query
      ->addTag('translatable');
    $query
      ->leftJoin('menu_router', 'm', 'm.path = ml.router_path');
    $query
      ->fields('ml');
    $query
      ->fields('m', array(
      'load_functions',
      'to_arg_functions',
      'access_callback',
      'access_arguments',
      'page_callback',
      'page_arguments',
      'delivery_callback',
      'tab_parent',
      'tab_root',
      'title',
      'title_callback',
      'title_arguments',
      'theme_callback',
      'theme_arguments',
      'type',
      'description',
    ));
    $query
      ->condition('ml.menu_name', $menu_name);

    // Fetch the mapped links and their descendants, sorted by depth.
    $or = db_or();
    for ($i = 1; $i <= MENU_MAX_DEPTH; $i++) {
      $p = 'ml.p' . $i;
      $query
        ->orderBy($p, 'ASC');
      $or
        ->condition($p, $mapped_links, 'IN');
    }
    $query
      ->condition($or);
    return $query
      ->execute()
      ->fetchAll();
  }
  return array();
}