You are here

function panels_page_menu in Panels 5.2

Same name and namespace in other branches
  1. 6.2 panels_page/panels_page.module \panels_page_menu()

Implementation of hook_menu().

File

panels_page/panels_page.module, line 44
panels_page.module

Code

function panels_page_menu($may_cache) {
  $items = array();
  $panels = panels_page_load_all();
  if ($may_cache) {
    $access = user_access('create panel-pages');
    $items[] = array(
      'path' => 'admin/panels/panel-page',
      'title' => t('Panel pages'),
      'access' => $access,
      'callback' => 'panels_page_passthru',
      'callback arguments' => array(
        'panels_page_list_page',
      ),
      'description' => t('Create and administer panel-pages (complex layout pages with URLs).'),
    );
    $items[] = array(
      'path' => 'admin/panels/panel-page/list',
      'title' => t('List'),
      'access' => $access,
      'callback' => 'panels_page_passthru',
      'callback arguments' => array(
        'panels_page_list_page',
      ),
      'weight' => -10,
      'type' => MENU_DEFAULT_LOCAL_TASK,
    );
    $items[] = array(
      'path' => 'admin/panels/panel-page/add',
      'title' => t('Add'),
      'access' => $access,
      'callback' => 'panels_page_passthru',
      'callback arguments' => array(
        'panels_page_add_page',
      ),
      'type' => MENU_LOCAL_TASK,
    );
    $items[] = array(
      'path' => 'admin/panels/panel-page/import',
      'title' => t('Import'),
      'access' => $access,
      'callback' => 'panels_page_passthru',
      'callback arguments' => array(
        'panels_page_import_page',
      ),
      'type' => MENU_LOCAL_TASK,
    );
    $items[] = array(
      'path' => 'admin/panels/panel-page/settings',
      'title' => t('Settings'),
      'access' => $access,
      'callback' => 'panels_page_settings',
      'weight' => 5,
      'type' => MENU_LOCAL_TASK,
    );
    $items[] = array(
      'path' => 'admin/panels/panel-page/disable',
      'access' => $access,
      'callback' => 'panels_page_passthru',
      'callback arguments' => array(
        'panels_page_disable_page',
      ),
      'weight' => -1,
      'type' => MENU_CALLBACK,
    );
    $items[] = array(
      'path' => 'admin/panels/panel-page/enable',
      'access' => $access,
      'callback' => 'panels_page_passthru',
      'callback arguments' => array(
        'panels_page_enable_page',
      ),
      'weight' => -1,
      'type' => MENU_CALLBACK,
    );

    // Get all panels and, if enabled, create menu items.
    foreach ($panels as $panel_page) {
      if (empty($panel_page->disabled)) {

        // Only create menu items based on the path if it's not a variable path.
        if (strpos($panel_page->path, '%') === FALSE) {
          _panels_page_create_menu_item($items, $panel_page, $panel_page->path, array(
            $panel_page->name,
            FALSE,
          ));

          // DEBUG: Above is now creating only the basic menu item, not the admin items.
        }
        panels_page_admin_menu_items($items, 'admin/panels/panel-page/' . $panel_page->name, $panel_page);
      }
    }
  }
  else {

    // Look for panels with variable arguments.
    // Build an array of $urls because 'real' URLs will take precedence over
    // argument filled URLs
    $urls = array();
    foreach ($panels as $panel_page) {
      $url[$panel_page->path] = TRUE;
    }
    $plugins_loaded = FALSE;
    foreach ($panels as $panel_page) {
      if (!empty($panel_page->disabled)) {
        continue;
      }
      if (strpos($panel_page->path, '%') !== FALSE) {
        $path = explode('/', $panel_page->path);

        // First pass:
        // Check if the current path sufficiently matches $panel_page->path,
        // which means: all fixed parts that come before the last %-wildcard
        // need to match, while trailing fixed parts don't matter.
        // We start with the last part and take up checking after reaching a %.
        $check = FALSE;
        foreach (array_reverse($path, TRUE) as $id => $chunk) {
          if ($chunk == '%') {
            $check = TRUE;
            continue;
          }
          if ($check && $chunk != arg($id)) {

            // Skip outer foreach loop to continue with the next $panel_page.
            continue 2;
          }
        }
        $args = array(
          $panel_page,
          FALSE,
        );

        // Second pass:
        $argument = reset($panel_page->arguments);

        // Get first argument.
        foreach ($path as $id => $chunk) {
          if ($chunk != '%') {
            continue;
          }

          // For arguments that are embedded in the URL, we require the
          // argument handler to return a context, if there is an argument handler.
          if ($argument) {

            // Try to avoid loading the plugins code unless necessary.
            if (!$plugins_loaded) {
              panels_load_include('plugins');
              $plugins_loaded = TRUE;
            }
            $context = panels_argument_get_context($argument, arg($id));
            if (!$context) {
              break;
            }
            $panel_page->context[panels_argument_context_id($argument)] = $context;
          }
          $path[$id] = arg($id);
          $args[] = arg($id);
          $argument = next($panel_page->arguments);

          // Get next argument.
        }
        _panels_page_create_menu_item($items, $panel_page, implode('/', $path), $args);

        // DEBUG: Above is now creating only the basic menu item, not the admin items.
      }
    }
  }
  return $items;
}