Hi there,
I am using the term_reference_tree to display a relatively big list of items (country name) divided by continent. The term_reference_tree provides a nice compact widget, and I like it very much.
Now, during the registration process, I want to restrict the list of countries to about 10 items (full list is still available after the registration). Usually I would simply use hook_form_alter and remove the unwanted items from the '#options' item of the taxonomy term field. But term_reference_tree does not use the '#options' mecanism, instead it read directly the terms from the DB to build the tree.
My question: what is the best way to alter/filter the tree before it is being rendered? is there a hook I could use?
Cheers,
S.
| Comment | File | Size | Author |
|---|---|---|---|
| #12 | term_reference_tree-added_alter_hook-1539238-12.patch | 346 bytes | alex_optim |
| #4 | term_reference_tree-added_alter_hook.patch | 547 bytes | napche |
Comments
Comment #1
drupal.ninja03 commentedHi,
I too am in dire need for the solution to this. Please ca someone point me in the right direction?
Thanks.
Comment #2
hillmark commentedYou could achieve this by using a view to return a filtered list. Not tried with a hierarchical taxonomy, but I added a field to my taxonomy, which in your case would be a 'visible at registration' Boolean. You can then build a view and filter it by your new field to limit the options returned. The setup for filtering the taxonomy using this view is straightforward after that.
Comment #3
Raghav1981 commentedhttp://drupal.stackexchange.com/questions/100225/programmatically-alter-...
this link will help you on how to alter/filter the tree.
Comment #4
napche commentedI added a patch which implements an alter hook right before rendering the tree.
In a recent project I used this to strip some values from the tree.
In your module, just use a my_module_ term_reference_get_children_alter($terms) function.
Comment #5
alex_optimComment #6
pifagor commentedLook good
Comment #7
alex_optimUpdate patch.
Comment #8
alex_optimComment #9
alex_optimUpdate patch.
Comment #10
alex_optimComment #11
pifagor commentedIn my opinion, we can use
drupal_alter('term_reference_get_children', $tree[$vid]);instead ofdrupal_alter('term_reference_get_children', $tree[$vid]['terms']);Comment #12
alex_optimComment #14
alex_optimComment #15
alex_optimComment #16
alex_optim