I have a view that generates a list of terms under a given parent. The preview of the view appears to return the results I'm looking for. (See below)

However - when using the filter by view option with term reference tree, no options are displayed on the node edit form. Could you help me figure out what I'm missing?
Thanks!

$view = new view;
$view->name = 'allowed_terms';
$view->description = '';
$view->tag = 'default';
$view->base_table = 'taxonomy_term_data';
$view->human_name = 'Allowed Terms';
$view->core = 7;
$view->api_version = '3.0-alpha1';
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */

/* Display: Master */
$handler = $view->new_display('default', 'Master', 'default');
$handler->display->display_options['access']['type'] = 'perm';
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['query']['type'] = 'views_query';
$handler->display->display_options['query']['options']['query_comment'] = FALSE;
$handler->display->display_options['exposed_form']['type'] = 'basic';
$handler->display->display_options['pager']['type'] = 'none';
$handler->display->display_options['pager']['options']['offset'] = '0';
$handler->display->display_options['style_plugin'] = 'default';
$handler->display->display_options['row_plugin'] = 'fields';
/* Relationship: Taxonomy term: Parent term */
$handler->display->display_options['relationships']['parent']['id'] = 'parent';
$handler->display->display_options['relationships']['parent']['table'] = 'taxonomy_term_hierarchy';
$handler->display->display_options['relationships']['parent']['field'] = 'parent';
$handler->display->display_options['relationships']['parent']['required'] = 1;
/* Field: Taxonomy term: Term ID */
$handler->display->display_options['fields']['tid']['id'] = 'tid';
$handler->display->display_options['fields']['tid']['table'] = 'taxonomy_term_data';
$handler->display->display_options['fields']['tid']['field'] = 'tid';
$handler->display->display_options['fields']['tid']['label'] = '';
$handler->display->display_options['fields']['tid']['alter']['alter_text'] = 0;
$handler->display->display_options['fields']['tid']['alter']['make_link'] = 0;
$handler->display->display_options['fields']['tid']['alter']['absolute'] = 0;
$handler->display->display_options['fields']['tid']['alter']['external'] = 0;
$handler->display->display_options['fields']['tid']['alter']['replace_spaces'] = 0;
$handler->display->display_options['fields']['tid']['alter']['trim_whitespace'] = 0;
$handler->display->display_options['fields']['tid']['alter']['nl2br'] = 0;
$handler->display->display_options['fields']['tid']['alter']['word_boundary'] = 1;
$handler->display->display_options['fields']['tid']['alter']['ellipsis'] = 1;
$handler->display->display_options['fields']['tid']['alter']['strip_tags'] = 0;
$handler->display->display_options['fields']['tid']['alter']['trim'] = 0;
$handler->display->display_options['fields']['tid']['alter']['html'] = 0;
$handler->display->display_options['fields']['tid']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['tid']['element_default_classes'] = 1;
$handler->display->display_options['fields']['tid']['hide_empty'] = 0;
$handler->display->display_options['fields']['tid']['empty_zero'] = 0;
$handler->display->display_options['fields']['tid']['hide_alter_empty'] = 0;
$handler->display->display_options['fields']['tid']['separator'] = '';
$handler->display->display_options['fields']['tid']['format_plural'] = 0;
/* Filter criterion: Taxonomy vocabulary: Machine name */
$handler->display->display_options['filters']['machine_name']['id'] = 'machine_name';
$handler->display->display_options['filters']['machine_name']['table'] = 'taxonomy_vocabulary';
$handler->display->display_options['filters']['machine_name']['field'] = 'machine_name';
$handler->display->display_options['filters']['machine_name']['value'] = array(
  'tags' => 'tags',
);
/* Filter criterion: Taxonomy term: Term */
$handler->display->display_options['filters']['tid']['id'] = 'tid';
$handler->display->display_options['filters']['tid']['table'] = 'taxonomy_term_data';
$handler->display->display_options['filters']['tid']['field'] = 'tid';
$handler->display->display_options['filters']['tid']['relationship'] = 'parent';
$handler->display->display_options['filters']['tid']['value'] = array(
  1 => '1',
);
$handler->display->display_options['filters']['tid']['reduce_duplicates'] = 0;
$handler->display->display_options['filters']['tid']['type'] = 'select';
$handler->display->display_options['filters']['tid']['vocabulary'] = 'tags';

Comments

jastraat’s picture

It looks like the problem has to do with if the parent itself isn't an 'allowed value' in the view - none of its children are either.

Line 289 of _term_reference_tree_get_term_hierarchy
if($filter == '' || array_key_exists($term->tid, $allowed)) {

This is checking to make sure that the PARENT tid is in the $allowed array before getting the terms children. Unfortunately this prevents having a view that allows only the children of a specific term.

bartk’s picture

Sounds like the best solution here would be to include an optional parent term so you don't *have* to use a view for this sort of thing. I'll see if I can add something to that effect.

Bart

jastraat’s picture

That would be awesome :)

jastraat’s picture

BartK,
Any word on this? Right now it's not possible using views to select all the descendents (multiple levels) of a parent, and the ability to limit the tree to anything below a certain ancestor would be fantastic for our use case.

bartk’s picture

Status: Active » Closed (fixed)

Added filter by parent term ID to widget settings in 7.x-1.x-dev.

drupalerocant’s picture

Hello,
I've just tried to use the parent ID filter and i couldn't make it work with neither module versions, stable nor dev.

bartk’s picture

Status: Closed (fixed) » Active

Use stable for now. It's pretty much up to date with dev.

What did you enter as the parent ID? It should be the taxonomy term ID number (and not the actual word).

drupalerocant’s picture

Hi!
This is the taxonomy terms i'm trying to filter,

Europa (Term ID=8)
-Bulgaria (Term ID=17)
-España (Term ID=13)
--Araba(Term ID=23)
--Bizkaia(Term ID=22)
--Burgos(Term ID=20)
--Cantabria(Term ID=19)
--Palencia(Term ID=21)
-Francia
-Polonia

The maximun depth i left it blank.
As the parent ID i entered 13, because in this content type (events) i want only to be able to choose the spanish regions.
Thanks for the help!

suldan’s picture

Doesn't work for me either (7.x-1.9). Do we have to allow multiple values?
Edit:
1. Seem to be a problem with limiting the values
2. Tested versions 1.4/1.6/1.9/latest dev
3. Get this error when saving settings with a 'filter by view' and/or 'parent term id' AND only one value allowed!
Notice: Undefined index: in _term_reference_tree_get_options() (line 792 xxx/term_reference_tree/term_reference_tree.module)
4. Everything work fine with unlimited values

PS its the taxonomy for structuring the menu (taxonomy menu) so I cant allow more than 1 value.

hephaestus’s picture

I was also unable to get filtering by Parent Term ID working in 7.x-1.9, however the patch on this issue got it working.

It would be nice to have the option for the parent to be shown and selectable, for those of us with "select parents automatically" enabled. For example with the following taxonomy, if you were filtering so it only showed children of "Fruit", it would make sense to still have "Fruit" selectable if the parents are automatically selected elsewhere.

+ Vegetable
- Onion
- Potato
+ Fruit
- Apple
- Banana
- Orange

duaelfr’s picture

Status: Active » Closed (duplicate)

As said in the previous comment, there is a patch which fix the parent tid field.
#1517994: Parent ID selection