Function : Administer > Content management > Content
Drupal path : admin/content/node
The category filter ignores vocabularies with only one term.
This means that :
1.) The category filter is not displayed unless you define a vocabulary with at least two terms.
2.) If more vocabularies exist, those with only one term do not appear in the category filter selector.
The same happens with the Advanced search function.
The cause of this is in taxonomy.module function taxonomy_form_all()
(comment is mine) :
function taxonomy_form_all($free_tags = 0) {
$vocabularies = taxonomy_get_vocabularies();
$options = array();
foreach ($vocabularies as $vid => $vocabulary) {
if ($vocabulary->tags && !$free_tags) { continue; }
$tree = taxonomy_get_tree($vid);
if ($tree && (count($tree) > 1)) { /* vocabularies with only one term are skipped */
$options[$vocabulary->name] = array();
foreach ($tree as $term) {
$options[$vocabulary->name][$term->tid] = str_repeat('-', $term->depth) . $term->name;
}
}
}
return $options;
}
I tested the following modification (see comment):
function taxonomy_form_all($free_tags = 0) {
$vocabularies = taxonomy_get_vocabularies();
$options = array();
foreach ($vocabularies as $vid => $vocabulary) {
if ($vocabulary->tags && !$free_tags) { continue; }
$tree = taxonomy_get_tree($vid);
if ($tree) { /* Process vocabularies with at least one term. Ignore empty vocabularies. */
$options[$vocabulary->name] = array();
foreach ($tree as $term) {
$options[$vocabulary->name][$term->tid] = str_repeat('-', $term->depth) . $term->name;
}
}
}
return $options;
}
I was not able to find any side-effects, and now all vocabularies with at least one term appear in the content filter selector.
Many thanks for comments/reviews
(patch against HEAD attached)
Comment | File | Size | Author |
---|---|---|---|
#2 | taxonomy_filter.patch | 861 bytes | riccardoR |
taxonomy_module_1.patch | 759 bytes | riccardoR | |
Comments
Comment #1
drummLooks like taxonomy_get_tree() always returns an array, so I do not think what was left of the if statement is actually useful. I think we do explicitly want to make sure there is one term, so
count(...) > 0
would be the condition to use.Comment #2
riccardoR CreditAttribution: riccardoR commented@drumm: thanks for your review. You are definitely right.
Rerolled with your commentary against current 5.x-dev
Comment #3
Dries CreditAttribution: Dries commentedCommitted this patch to CVS HEAD. I think we might want to backport this patch to D5.
Comment #4
drummCommitted to 5.x.
Comment #5
drummComment #6
(not verified) CreditAttribution: commented