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,
    );
}

Comments

ciderpunx’s picture

Apologies if this question is a bit basic, but I am only a part-time drupalist.

Where exactly do I put this code?

I am wanting to filter an exposed form in a view to remove unpublished taxonomy terms from the select list that it makes. It seems like hook_form_alter would normally go in a custom module and be called for all forms on the site, is this what is intended here?

Also, I am not clear of what 'my_options_1' is doing. Is this the name of a new select list that will be added to our form and, if so, how would I swap it for the existing select list.

balintcsaba’s picture

Hi,

You need to activate the Taxonomy Publisher Filter and sett the permissions ( before don't forget to sett the Publish setting for the Vocabulary you wish to filter at http://www.yoursite/admin/config/taxonomy-tools/publisher) for the module and it will filter ....... that example is for custom form. For Views or Form Display is working automatically. Just follow the step above at "Hove to use" section.
Sorry for the late answer.

Let me know if you succeed with the module.

With Respect,
Csaba

We all die. The goal isn't to live forever, the goal is to create something that will.

ciderpunx’s picture

Hi Csaba

You need to activate the Taxonomy Publisher Filter and sett the permissions ( before don't forget to sett the Publish setting for the Vocabulary you wish to filter at http://www.yoursite/admin/config/taxonomy-tools/publisher) for the module and it will filter

I've enabled the module.

I have selected the vocabulary which I want filtered.

I have chosen a term in that vocabulary and set that term to "unpublished".

Attempting to access the term gives an unauthorized error as expected.

However, the term is still present in my select element in the exposed filter on my page.

I have tried setting the permissions for the filter on and off. Neither option has any visible effect (caching disabled for the purposes of testing).

balintcsaba’s picture

Hi ciderpunx,

I will write step by step what you have to do. If you make this steps and still not work then please post an issue to Taxonomy Tools project page with your problem and provide many information you can.

Step 1.
Activate the 2 module Taxonomy Publisher and Taxonomy Publisher Filter.
Step 2
In configuration section of the Drupal 7 you will find the 2 module settings page. First check the check-box for the vocabulary(s) you wish to filter at Taxonomy Publisher. Then go to the Taxonomy Publisher Filter (you said that you don't wont the cache feature so uncheck that).
Step 3
Clear Drupal cache. And unpublish the terms you wish to be hidden for some roles.
Step 4
Go to permission page and find the Taxonomy Publisher Filter section. If you are using Views you are interested in this kind of permissions : Views filter - use publish for taxonomy vocabulary Your Vocabulary Name :.
Now check the permission for the role you wish to filter the module.
Step 5
Clear Drupal cache.
Step 6
Log in with an user part of that role you checked at the permission. At check if it's working.

If still not working one more thing left to check. Go to module, find the taxonomy_publisher_filter_form_views_exposed_form_alter function and print out the $form variable witch must contain a $form['#info']. This is very important for filter to work, if some custom module of yours or maybe a contrib module (but i don't thinks so) removed from the form then the filter wont work. If this is ok then post the issue.

We all die. The goal isn't to live forever, the goal is to create something that will.

ciderpunx’s picture

OK, thanks for reply. I will check out taxonomy_publisher_filter_form_views_exposed_form_alter and let you know what it says.