You are here

usersearchtoadmin.module in User Search to People Administration 7

Moves user search form and results from search/ to admin/people.

File

usersearchtoadmin.module
View source
<?php

/**
 * @file
 * Moves user search form and results from search/ to admin/people.
 */

/**
 * Implements hook_menu_alter().
 *
 * Move en todo user search tab from overall search to People administration.
 */
function usersearchtoadmin_menu_alter(&$items) {
  $module = 'user';
  $new_base_path = 'admin/people';
  $new_title = t("Search");

  // Below could move any set of menu items by defining inputs above.
  $item_indexes = array(
    'search/' . $module => $new_base_path . '/search',
    'search/' . $module . '/%menu_tail' => $new_base_path . '/search/%menu_tail',
  );
  foreach ($item_indexes as $item_index => $new_item_index) {
    if (isset($items[$item_index])) {
      $item = $items[$item_index];
      unset($items[$item_index]);
      $item['title'] = $new_title;
      $item['weight'] = -10;
      if (substr($item_index, -11) == '/%menu_tail') {
        $item['page arguments'] = array(
          'user',
          3,
        );

        // These tabs are not subtabs.
        $item['tab_root'] = $new_base_path;

        // These tabs need to display at the same level.
        $item['tab_parent'] = $new_base_path . '/search';
      }
      $items[$new_item_index] = $item;
    }
  }
}

/**
 * Implements hook_form_FORM_ID_alter().
 */
function usersearchtoadmin_form_search_form_alter(&$form, &$form_state) {
  $action = 'admin/people/search';
  $form['#action'] = url($action);

  // Record the $action for later use in redirecting.
  $form_state['action'] = $action;
}