You are here

function apachesolr_search_menu_alter in Apache Solr Search 8

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

File

./apachesolr_search.module, line 164
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();

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

    // Validate the environemnt ID in case of import or missed deletion.
    $environment = apachesolr_environment_load($search_page['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 we are simulating a core search tab.
    $core_search = $parts[0] == 'search';
    $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'),
    );

    // 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 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 && !empty($position)) {
      $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,
      );
      $items[$search_page['search_path'] . '/%']['title callback'] = $title_callback;
      $items[$search_page['search_path'] . '/%']['title arguments'] = array(
        $search_page['page_id'],
        $position,
      );
    }

    // 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'];
    }
  }
}