You are here

function _search_restrict_advanced_form in Search Restrict 6

Same name and namespace in other branches
  1. 6.2 search_restrict.module \_search_restrict_advanced_form()
  2. 7 search_restrict.module \_search_restrict_advanced_form()

Remove restricted content types from the advanced search form. We use after_build due to the method the node module uses to add the advanced search options.

1 string reference to '_search_restrict_advanced_form'
search_restrict_form_alter in ./search_restrict.module
Implementation of hook_form_alter().

File

./search_restrict.module, line 128

Code

function _search_restrict_advanced_form($form_element, &$form_state) {
  global $user;
  if ($user->uid == 1) {
    return $form_element;
  }
  $types = node_get_types();
  $role_ids = array_keys($user->roles);
  foreach ($types as $type => $type_info) {
    $access = FALSE;
    $roles = variable_get('search_restrict_type_' . $type, array());
    if (empty($roles)) {
      $access = TRUE;
    }
    else {
      foreach ($roles as $role_id => $selected) {
        if (!empty($selected) && in_array($role_id, $role_ids)) {
          $access = TRUE;
          break;
        }
      }
    }
    if (!$access) {
      unset($form_element['advanced']['type']['#options'][$type]);
      unset($form_element['advanced']['type'][$type]);
    }
  }
  return $form_element;
}