You are here

function _permissions_by_term_remove_restricted_items_in_select_field in Permissions by Term 7

Removes restricted items in select field.

Parameters

$form:

$filter_name:

$user:

Return value

null

1 call to _permissions_by_term_remove_restricted_items_in_select_field()
permissions_by_term_form_views_exposed_form_alter in ./permissions_by_term.module
Implements hook_form_views_exposed_form_alter().

File

./permissions_by_term.module, line 466
Allows access to terms in a vocabulary to be limited by user or role.

Code

function _permissions_by_term_remove_restricted_items_in_select_field(&$form, $filter_name, $user) {
  foreach ($form[$filter_name] as $form_element) {
    if (is_array($form_element)) {
      foreach ($form_element as $k => $option) {
        if (is_object($option)) {
          $term = taxonomy_term_load($k);
        }
        else {
          $term = taxonomy_get_term_by_name($option);
        }
        if (is_array($term)) {
          foreach ($term as $term_info) {
            $term_id = $term_info->tid;
            if (!permissions_by_term_allowed($term_id, $user)) {
              unset($form[$filter_name]['#options'][$term_id]);
            }
          }
        }
      }
    }
  }
}