You are here

function apachesolr_search_menu_alter in Apache Solr Search 7

Same name and namespace in other branches
  1. 8 apachesolr_search.module \apachesolr_search_menu_alter()
  2. 6.3 apachesolr_search.module \apachesolr_search_menu_alter()
  3. 6 apachesolr_search.module \apachesolr_search_menu_alter()
  4. 6.2 apachesolr_search.module \apachesolr_search_menu_alter()

File

./apachesolr_search.module, line 166
Provides a content search implementation for node content for use with the Apache Solr search application.

Code

function apachesolr_search_menu_alter(&$items) {

  // Gets default search information.
  $default_info = search_get_default_module_info();
  $search_types = apachesolr_search_load_all_search_types();
  $search_pages = apachesolr_search_load_all_search_pages();
  $default_search_page = apachesolr_search_default_search_page();

  // Iterates over search pages, builds menu items.
  foreach ($search_pages as $search_page) {

    // Validate the environment ID in case of import or missed deletion.
    $env_id = $search_page['env_id'] == -1 ? variable_get('apachesolr_default_environment', '') : $search_page['env_id'];
    $environment = apachesolr_environment_load($env_id);
    if (!$environment) {
      continue;
    }

    // Parses search path into it's various parts, builds menu items dependent
    // on whether %keys is in the path.
    $parts = explode('/', $search_page['search_path']);
    $keys_pos = count($parts);

    // Tests whether apachesolr_search is the only enabled search module (in
    // which case there are no tabs).
    $active_module_info = search_get_info();
    $no_tabs = sizeof($active_module_info) == 1 && isset($active_module_info['apachesolr_search']) && count($search_pages) == 1;

    // Tests whether we are simulating a core search tab.
    $core_search = $parts[0] == 'search' && !$no_tabs;
    $position = array_search('%', $parts);
    $page_title = isset($search_page['page_title']) ? $search_page['page_title'] : 'Search Results';

    // If we have a taxonomy search, remove existing menu paths
    if ($search_page['search_path'] == 'taxonomy/term/%') {
      unset($items['taxonomy/term/%taxonomy_term']);
      unset($items['taxonomy/term/%taxonomy_term/view']);
    }

    // Replace possible tokens [term:tid], [node:nid], [user:uid] with their
    // menu-specific variant
    $items[$search_page['search_path']] = array(
      'title' => $page_title,
      'page callback' => 'apachesolr_search_custom_page',
      'page arguments' => array(
        $search_page['page_id'],
        '',
        $position,
      ),
      'access arguments' => array(
        'search content',
      ),
      'type' => $core_search ? MENU_LOCAL_TASK : MENU_SUGGESTED_ITEM,
      'file' => 'apachesolr_search.pages.inc',
      'file path' => drupal_get_path('module', 'apachesolr_search'),
    );
    if ($search_page['page_id'] == $default_search_page) {
      $items[$search_page['search_path']]['weight'] = -5;
    }

    // Not using menu tail because of inflexibility with clean urls
    $items[$search_page['search_path'] . '/%'] = array(
      'title' => $page_title,
      'page callback' => 'apachesolr_search_custom_page',
      'page arguments' => array(
        $search_page['page_id'],
        $keys_pos,
        $position,
      ),
      'access arguments' => array(
        'search content',
      ),
      'type' => !$core_search ? MENU_CALLBACK : MENU_LOCAL_TASK,
      'file' => 'apachesolr_search.pages.inc',
      'file path' => drupal_get_path('module', 'apachesolr_search'),
    );
    if ($search_page['page_id'] == $default_search_page) {
      $items[$search_page['search_path'] . '/%']['weight'] = -5;
    }

    // If title has a certain callback for the selected type we use it
    $search_type_id = !empty($search_page['settings']['apachesolr_search_search_type']) ? $search_page['settings']['apachesolr_search_search_type'] : FALSE;
    $search_type = !empty($search_types[$search_type_id]) ? $search_types[$search_type_id] : FALSE;
    if ($search_type) {
      $title_callback = $search_type['title callback'];
      $items[$search_page['search_path']]['title callback'] = $title_callback;
      $items[$search_page['search_path']]['title arguments'] = array(
        $search_page['page_id'],
        $position,
        $keys_pos,
      );
      $items[$search_page['search_path'] . '/%']['title callback'] = $title_callback;
      $items[$search_page['search_path'] . '/%']['title arguments'] = array(
        $search_page['page_id'],
        $position,
        $keys_pos,
      );
    }

    // If we have additional searches in the search/* path
    if ($core_search) {
      $items[$search_page['search_path'] . '/%']['tab_root'] = 'search/' . $default_info['path'] . '/%';
      $items[$search_page['search_path'] . '/%']['tab_parent'] = 'search/' . $default_info['path'];
    }
  }
}