Convention for displaying term hierarchy

Created on 1 March 2012, almost 13 years ago
Updated 17 June 2023, over 1 year ago

I was hoping we could create and document a standard for displaying term hierarchy in Drupal core and contrib modules. Currently term hierarchy in core ( Term reference fields) are displayed like such:

Term A
-Term A1
-Term A2
--Term A2Z
--Term A2Y
-Term A3
Term B
Term C
-Term C1

The problem is some contrib modules do not follow this convention. Here's a quick grep of a project I'm working on:

$ grep -rn "str_repeat('-', \$term->depth)" . | grep -v ".svn"
./modules/field/modules/options/options.api.php:63: $options[$term->tid] = str_repeat('-', $term->depth) . $term->name;
./modules/taxonomy/taxonomy.module:1482: $options[$term->tid] = str_repeat('-', $term->depth) . $term->name;
./sites/all/modules/i18nviews/includes/i18nviews_handler_filter_taxonomy_index_tid.inc:50: $choice->option = array($term->tid => str_repeat('-', $term->depth) . i18n_taxonomy_term_name($term));
./sites/all/modules/custom_search/modules/custom_search_taxonomy/custom_search_taxonomy.module:67: $options['c-' . $term->tid] = (drupal_substr(variable_get('custom_search_' . $delta . 'voc' . $voc->vid . '_selector', 'disabled'), 0, 6) == 'select') ? str_repeat('-', $term->depth) . ' ' . $term->name : $term->name ;
./profiles/temp/modules/contrib/ctools/plugins/access/term.inc:70: $terms[$term->tid] = str_repeat('-', $term->depth) . ($term->depth ? ' ' : '') . $term->name;
./profiles/temp/modules/contrib/ctools/plugins/access/term_has_parent.inc:73: $terms[$term->tid] = str_repeat('-', $term->depth) . ($term->depth ? ' ' : '') . $term->name;
./profiles/temp/modules/contrib/context/plugins/context_condition_node_taxonomy.inc:33: $options[$vocabulary->name][$term->tid] = str_repeat('-', $term->depth) . $term->name;
./profiles/temp/modules/contrib/i18n/i18n_taxonomy/i18n_taxonomy.module:358: $options[$term->tid] = str_repeat('-', $term->depth) . i18n_taxonomy_term_name($term);
./profiles/temp/modules/contrib/i18n/i18n_taxonomy/i18n_taxonomy.module:869: $options[$vname][$term->tid] = str_repeat('-', $term->depth) . i18n_taxonomy_term_name($term);
./profiles/temp/modules/contrib/views/modules/taxonomy/views_handler_filter_term_node_tid.inc:126: $choice->option = array($term->tid => str_repeat('-', $term->depth) . $term->name);

As outlined above, core has no space between the leading '-' and the term name. Various contrib modules will follow this. One example above hardcodes the space in between leading '-' and term name. Ctools, in my opinion, handles it best by concatenating a space if we're at a sub-level term:

($term->depth ? ' ' : '')

I recently ran in to an issue where another module which enabled you to search the options wouldn't return results when searching for a term name because of the prefixed '-' . In addition to this, I feel like a space between the '-' and the term name looks better visually. Thoughts?

✨ Feature request
Status

Postponed: needs info

Version

9.5

Component
UI textΒ  β†’

Last updated 5 days ago

No maintainer
Created by

πŸ‡¨πŸ‡¦Canada evanbarter

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024