Only show vocabulary assigned to selected content-type
MarcElbichon - February 25, 2008 - 12:36
| Project: | Link to content |
| Version: | 5.x-2.x-dev |
| Component: | Code |
| Category: | task |
| Priority: | normal |
| Assigned: | stBorchert |
| Status: | active |
Jump to:
Description
Actually, all vocabularies are shown in the first drop down list. Should be better to see only those assigned to selected content-types in the admin section.
To do this, in linktocontent_node.module, in the _linktocontent_node_get_categories function, replace :
<?php
foreach ($containers as $item) {
$obj = new StdClass;
$obj->vid = $item->vid;
$obj->tid = ($top ? $item->vid : $item->tid);
$obj->title = (trim($item->name));
$results[] = $obj;
} // end foreach
return $results;
?>by
<?php
$status = variable_get('linktocontent_node_content_types', array());
foreach ($containers as $item) {
$obj = new StdClass;
if (isVocabularyForContainer($item->nodes,$status)) {
$obj->vid = $item->vid;
$obj->tid = ($top ? $item->vid : $item->tid);
$obj->title = (trim($item->name));
$results[] = $obj;
}
} // end foreach
return $results;
?>and add the function as below :
<?php
function isVocabularyForContainer($container, $vocabularies) {
$nopresent = array_diff($vocabularies, $container);
return (! (count($nopresent) == count($vocabularies)));
}
?>Is this feature could be include in the next patch ?

#1
Hi Marc.
Thanks for your feedback.
I hope to be able to create a new version (5.2.x) within the next weeks (or finally start with coding on it).
This feature will be in it definitely.
thanks again,
Stefan
#2
moved task to new development version
#3
The suggestion works great but needs a tweak.
In the loop of the 'containers' it assumes it's always dealing with a vocabulary and not the final terms.
This means when you're at the lowest level (terms) you're testing in isVocabularyForContainer returns errors as terms node does not have a nodes attribute.
I recommend this solution:
<?php$status = variable_get('linktocontent_node_content_types', array());
foreach ($containers as $item) {
$obj = new StdClass;
if ($container > 0 || isVocabularyForContainer($item->nodes,$status)) {
$obj->vid = $item->vid;
$obj->tid = ($top ? $item->vid : $item->tid);
$obj->title = (trim($item->name));
$results[] = $obj;
}
} // end foreach
return $results;
?>