You are here

function _search_restrict_advanced_form in Search Restrict 7

Same name and namespace in other branches
  1. 6.2 search_restrict.module \_search_restrict_advanced_form()
  2. 6 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
Implements hook_form_alter().

File

./search_restrict.module, line 120
Restrict by role who can search for each content type.

Code

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