You are here

function apachesolr_search_menu_alter in Apache Solr Search 6.3

Same name and namespace in other branches
  1. 8 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 163
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.
  $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 environment ID in case of import or missed deletion.
    $environment = apachesolr_environment_load($search_page['env_id']);
    if (!$environment) {
      continue;
    }
    $search_page = apachesolr_search_page_load($search_page['page_id']);
    if (!$search_page) {
      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';
    $taxonomy_search = $search_page['search_path'] == 'taxonomy/term/%';
    $position = array_search('%', $parts);
    $page_title = isset($search_page['page_title']) ? $search_page['page_title'] : 'Search Results';

    // 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'),
    );
    $items[$search_page['search_path'] . '/%menu_tail'] = array(
      'title' => $page_title,
      'load arguments' => array(
        '%map',
        '%index',
      ),
      'page callback' => 'apachesolr_search_custom_page',
      'page arguments' => array(
        $search_page['page_id'],
        $keys_pos,
        $position,
      ),
      'access arguments' => array(
        'search content',
      ),
      'type' => $taxonomy_search ? MENU_DEFAULT_LOCAL_TASK : 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'] . '/%menu_tail']['title callback'] = $title_callback;
      $items[$search_page['search_path'] . '/%menu_tail']['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'] . '/%menu_tail']['tab_root'] = 'search/' . $default_info['path'] . '/%';
        $items[$search_page['search_path'] . '/%menu_tail']['tab_parent'] = 'search/' . $default_info['path'];
      }*/
    if ($taxonomy_search) {
      unset($items['taxonomy/term/%taxonomy_term']);
      unset($items['taxonomy/term/%taxonomy_term/view']);
    }
  }
}