Advertising sustains the DA. Ads are hidden for members. Join today

Taxonomy Publisher Filter

Last updated on
30 April 2025

Dependencies

It depends on the Taxonomy Publisher module (now part of the Taxonomy tools project), which
attaches a status field to the taxonomy terms of the vocabularies you select.

Versions

The current version supports select, checkbox/radio and autocomplete widgets for term reference fields.

How to use

  1. download the module and place it under 'sites/all/modules/contrib' folder
    • with Drush use: drush dl taxonomy_tools
  2. enable the module from the modules page: 'admin/build/modules' the Taxonomy Publisher & Taxonomy Publisher Filter module
  3. enable taxonomy publisher on the vocabularies you wish to limit
  4. enable/disable the terms in the above vocabularies
  5. configure roles that show see the limited list only under admin/people/permission

Custom Form

_taxonomy_publisher_filter_custom_form($vid, $settings) function is helpful to filter your select or checkbox/radio field in custom forms.
The function will expect a vocabulary id by default and will return the filtered option list.

    $option = _taxonomy_publisher_filter_custom_form($vid);

Also is having an optional array parameter where you can sett to cache the result (very useful with big vocabulary) and to use the module permission settings for the vocabulary you filter.

    $settings = array();
    $settings['by_role'] = TRUE;
    $settings['cache'] = $form_id;
    $option = _taxonomy_publisher_filter_custom_form($vid,$settings);

If the $settings['by_role'] is not sett or is FALSE will filter the vocabulary for all roles.
Even if is optional is indicated to use the cache feature and if you do so to avoid cache conflict use the form ID to his value.

Exemple:

function hook_form_alter(&$form, &$form_state, $form_id) {
    $settings = array();
    $settings['by_role'] = TRUE;
    $settings['cache'] = $form_id; 
    $options = _taxonomy_publisher_filter_custom_form($vid, $settings);
    $form['my_options_1'] = array(
      '#type' => 'select',
      '#title' => t('My List'),
      '#options' => $options,
    );
}

Help improve this page

Page status: Not set

You can: