Why is it that a term reference field can only use one vocabulary? What if we need to reference terms from more than one vocabulary? It is possible on node reference fields to choose the different content types to show nodes to be referenced.
As a start we can alter the form element in taxonomy_field_settings_form() to show checkboxes instead of a select list. e.g.
function taxonomy_field_settings_form($field, $instance, $has_data) {
// Get proper values for 'allowed_values_function', which is a core setting.
$vocabularies = taxonomy_vocabulary_load_multiple(FALSE);
$options = array();
foreach ($vocabularies as $vocabulary) {
$options[$vocabulary->machine_name] = $vocabulary->name;
}
$form['allowed_values'] = array(
'#tree' => TRUE,
);
foreach ($field['settings']['allowed_values'] as $delta => $tree) {
$form['allowed_values'][$delta]['vocabulary'] = array(
'#type' => 'checkboxes', // <-- Use checkboxes here, instead of 'select'
'#title' => t('Vocabulary'),
'#default_value' => $tree['vocabulary'],
'#options' => $options,
'#required' => TRUE,
'#description' => t('The vocabulary which supplies the options for this field.'),
'#disabled' => $has_data,
);
$form['allowed_values'][$delta]['parent'] = array(
'#type' => 'value',
'#value' => $tree['parent'],
);
}
return $form;
}
Comments
Comment #1
manuel garcia commentedYou can probably do that today using Entity reference module.
Comment #2
manuel garcia commentedA comment on my previous comment, if you use entity reference, then the reference will not be saved by taxonomy, and taxonomy/term/TID will not pickup the nodes assigned by entity reference. So depending on your needs, it might not be the solution.
Comment #3
ronline commentedI have tested the Entity reference, and as mentioned Manual Garcias, the taxonomy/term/TID doesn't pickup the nodes assigned by entity reference. Is there any other solution to use multiple vocabularies in term reference fields?
Comment #4
jonhattanhttp://drupal.org/project/vocabulary_reference
I haven't tested it though.
Comment #5
caschbre commented@Manual... can you expand upon your comment about using entity reference? I'm not quite sure I follow.
Comment #6
girishmuraly commentedI have created a D7 project https://drupal.org/project/combined_termref for this while awaiting a D8 addition.
Comment #7
manuel garcia commented@caschbre what i mean is that you use entity reference to "tag" a node with the term "X", if you go to taxonomy/term/X, the node will not be listed there.
So basicaly whatever is happening on the callback for taxonomy/term/% is not aware of nodes tagged using an entity reference field. I suppose that's a patch for entity reference, if it's stil the case...
Comment #8
caschbre commentedAh, I gotcha. You could override the taxonomy/term/% menu and use Views to render content "tagged" with the entity reference field.
Comment #9
larskoeie commentedIs this issue on the D8 to-do ? Anyone knows ?
Comment #10
ismail cherri commented@Manuel Garcia
I tested this scenario with entity reference field referencing two vocabs (Tags, and another one) for Article content type; it appeared on both pages whether using the default taxonomy in Drupal or using the given Taxonomy view in views.
Comment #11
manuel garcia commented@necromancerfinal I havent tested it since then, perhaps it got fixed already?
Comment #12
rjraman commented@Manuel Garcia Yes, it is working now. We can able to select more than one vocabulary using entity reference field.
Comment #13
rooby commentedRe #9: If someone posts a patch it possibly has a chance of getting into drupal 8. Otherwise it definitely won't I would think.
Comment #14
alifspb commentedi find simple way to do just look this
1. Go to Manage fields and >>Edit filed >>
>>Collection field settings
These settings apply to the Collection field everywhere it is used. Because the field already has data, some settings can no longer be changed.
Number of values >>> put unlimited
Maximum number of values users can enter for this field.
Vocabulary * which one you want to add
The vocabulary which supplies the options for this field.
2. go to
Change widget
Widget type * Check box/radio box
The type of form element you would like to present to the user when creating this field in the Accessories type.
please let me know if you get help from this thanks
www.life-tech.ru
Comment #15
alifspb commentedi find simple way to do just look this
1. Go to Manage fields and >>Edit filed >>
>>Collection field settings
These settings apply to the Collection field everywhere it is used. Because the field already has data, some settings can no longer be changed.
Number of values >>> put unlimited
Maximum number of values users can enter for this field.
Vocabulary * which one you want to add
The vocabulary which supplies the options for this field.
2. go to
Change widget
Widget type * Check box/radio box
The type of form element you would like to present to the user when creating this field in the Accessories type.
please let me know if you get help from this thanks
www.life-tech.ru
this is for D7
Comment #16
alifspb commentedComment #17
girishmuraly commented@alifspb the original description was to allow mutliple vocabularies for a term reference field. Not multiple values for a term ref field. Looks like you got that mixed up.
Comment #18
rooby commentedReverting original post back to its previous content.
Comment #19
jenlamptonIt looks like entity reference is already in core for D8 - so that should solve the problem: https://drupal.org/node/1801304
Closing this issue as duplicate.
Comment #20
stefan.r commentedJust in case anyone still has this issue in D7: the dev version of https://drupal.org/project/combined_termref allows adding multiple vocabularies (as many as are available on the system, not just the 3 vocabularies mentioned in the module description).
Comment #21
ravi shankar karnati commentedHello stefan, while using https://drupal.org/project/combined_termref it allows me maximum three only, but how can add more than 3 (multiple vocabularies ) ? How can i get it ? Please help me out.
Thanks a lot
Comment #22
georgir commentedOk, so it seems multiple vocabularies are "almost" supported in core as it is, the interface to set them up is not available though.
The combined_termref module just adds that admin interface. Kinda, sorta. It adds options for two extra vocabularies every time you open the field settings. So if you want to have 6 vocabularies, you have to edit it 3 times, adding more and more each.
It also has a weird choice for what to do when you unset some vocabulary - it repeats the first one instead of completely removing the item from the allowed_values array.
While I guess we could improve combined_termref, I really see no reason this shouldn't be fixed in core instead.
Oh, BTW you can make do without combined_termref as well - if you export your field to a feature, you can just edit the generated feature and add vocabularies to its allowed_values array.
EDIT: Oh well, I guess the key is in: "almost" supported in core as it is.
Some contrib modules may have relied on the 1-vocabulary limitation of the UI and so may need to be updated as well. For example, I am working on fixing term_reference_tree to work with multiple vocabularies right now. Another possible case might be exposed filters of views, based on an issue in the combined_termref issue list (but I've not tested personally to be sure if it is still applicable).
Comment #23
stefan.r commented@georgir it may be a nice-to-have, I have used combined_termref for multiple vocabularies in several projects.
Just not sure if this is something we can still get into 7.x... and there's no patch yet :)