You are here

function permissions_by_term_form_views_exposed_form_alter in Permissions by Term 7

Implements hook_form_views_exposed_form_alter().

File

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

Code

function permissions_by_term_form_views_exposed_form_alter(&$form, $form_state) {
  global $user;
  $filter_names = array();

  // Gather all filters.
  foreach ($form['#info'] as $filter) {
    $filter_names[] = $filter['value'];
  }

  // Remove not allowed options.
  foreach ($filter_names as $filter_name) {
    _permissions_by_term_remove_restricted_items_in_select_field($form, $filter_name, $user);

    // Modify the autocomplete path, to remove restricted taxonomy term items.
    if (!empty($form[$filter_name]['#autocomplete_path'])) {
      $vocabulary_id = explode('taxonomy/', $form[$filter_name]['#autocomplete_path']);
    }
    if (!empty($vocabulary_id['1'])) {
      $vocabulary_id = $vocabulary_id['1'];
      $form[$filter_name]['#autocomplete_path'] = 'permissions-by-term/' . 'autocomplete_terms/' . $vocabulary_id;
    }
  }
}