Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Hi,
Is there a way to add a "parent term" as with cck taxonomy?
I have a hierarchical taxonomy and i'd like to let a user choose only from one term and its children from the whole taxonomy.
Example:
- First
-- First Child
--- First Grandchild
- Second
-- Second Child
I'd like to exhibit to user only term 'First' and its children.
How can i do this?
Thanks
Comments
Comment #1
joachim CreditAttribution: joachim commentedThat's not something we're going to support in this module, because it goes beyond the stated purpose.
However, I reckon you could do that with hook_form_alter(), changing the list of taxonomy terms in the options array.
Comment #2
carvalhar CreditAttribution: carvalhar commentedHi Joachim,
Thanks for point me where to start. But could you provide more info?
I mean, user_term load terms at function user_terms_form_profile, right here:
$vocabulary = taxonomy_vocabulary_load($vid);
Isn't so? Shouldn't be there to edit the parent terms?
At content_taxonomy (where i saw the option to select a parent term and its children) there is this function:
$default_terms = taxonomy_get_children($parent, $field['vid']);
So, for my specif case i should do at user_terms_form_profile:
$vocabulary = taxonomy_get_children($parent, $vid);
I don't like to hack modules, but I don't know how can i do this using form_alter...which form should i change (i'm not using cck content type)? Is there a way to hook user_terms_form_profile?
Thanks,
Carlos
Comment #3
joachim CreditAttribution: joachim commenteduser_terms_form_profile() is called by hook_user(), which in turn is building up a form, so
in a hook_form_alter() will tell you which form you need to alter :)