0

I have a select list of taxonomy terms, all terms are needed for searching in views, but I don't need for insert new content. I wrote a custom module, which Hook should I use to hide some terms of my select list?

0

Use hook_form_FORM_ID_alter

/**
 * Implements hook_form_FORM_ID_alter.
 */
function my_module_form_views_exposed_form_alter(&$form, &$form_state, $form_id) {
  $vocabulary_machine_name = 'my_vocabulary'; // Makes the search faster.
  $term_names = array(
    'Term 1',
    'Term 2',
    'Term 3',
  );

  foreach ($term_names as $term_name) {
    $term = taxonomy_get_term_by_name($term_name, $vocabulary_machine_name);
    unset($form['my_field']['#options'][array_pop($term)->tid]);
  }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.