You are here

function _panels_page_menu_alter in Panels 6.2

Workhorse function for hook_menu_alter(); separated out here to reduce code weight.

Parameters

array $callbacks:

1 call to _panels_page_menu_alter()
panels_page_menu_alter in panels_page/panels_page.module
Implementation of hook_menu_alter().

File

panels_page/panels_page.menu.inc, line 178
panels_page.menu.inc

Code

function _panels_page_menu_alter(&$callbacks) {
  $panels_items = panels_page_create_menu_structure();
  if (empty($panels_items)) {

    // no point in trying to match when there is nothing to match...
    return;
  }

  // Build up an array with ONLY the items with args on native paths (overrides)
  $overrides = array_keys(array_filter($panels_items['metadata'], '_panels_page_menu_item_filter'));
  $matches = array();
  foreach ($panels_items['metadata'] as $raw_path => $metadata) {

    // Skip static panel_pages.
    if (!($metadata->load_flags & PANELS_IS_DYNAMIC)) {
      continue;
    }

    // Ensure that the path var is properly initialized on each iteration.
    $path = $raw_path;

    // Presence of a native path indicates that there are menu item properties
    // that need to be inherited.
    if (isset($metadata->native_path)) {
      if (in_array($raw_path, $overrides)) {

        // Use the native path because it will always match the overridden path
        // exactly (that is, it will always include the load function name).
        $path = $metadata->native_path;
        $matches[$path] = TRUE;
      }
      else {
        $map = explode('/', $raw_path);
        foreach ($map as $i => $arg) {
          if ($arg === '%') {
            $map[$i] = '%' . array_shift($metadata->load_functions);
          }
        }
        $path = implode('/', $map);
      }
      $panels_items['menu items'][$path] = array_merge($callbacks[$metadata->native_path], $panels_items['menu items'][$raw_path]);
      $panels_items['metadata'][$path] = $panels_items['metadata'][$raw_path];

      // Only unset if the original path  is different (e.g. taxonomy isn't)
      if ($raw_path != $path) {
        unset($panels_items['menu items'][$raw_path], $panels_items['metadata'][$raw_path]);
      }
    }

    // Update the load flags to reflect the status of a fallback router. It's
    // fine that static panel_pages miss this, they never have fallback routers.
    $metadata->load_flags |= !empty($matches[$path]) ? PANELS_HAS_FALLBACK_ROUTER : 0;
    db_query('UPDATE {panels_page} SET load_flags = %d WHERE pid = %d', $metadata->load_flags, $metadata->pid);

    // If a special menu builder function has been defined, fire it. Mostly an
    // edge case atm, node/add is the only existing argument plugin using this
    if (isset($metadata->menu_builder)) {
      $builder_items = array();
      $func = $metadata->menu_builder;
      if ($func($builder_items, $metadata)) {
        unset($panels_items['menu items'][$metadata->path]);
      }
      while (list($key, ) = each($builder_items)) {
        $builder_items[$key]['module'] = 'panels_page';
      }
      $panels_items['menu items'] = array_merge($builder_items, $panels_items['menu items']);
    }
  }

  // Insert all overridden routers into our separate router storage table, merge
  // all the panels menu items into the callback stack, then tuck the menu data
  // back into the static cache for hook_menu_link_alter() to get at later.
  _panels_page_menu_router_build($callbacks, $matches);
  $callbacks = array_merge($callbacks, $panels_items['menu items']);
  panels_page_create_menu_structure($panels_items);
}