I've found the solution by myself. It works without the TVI module.
Useful, but not required modules: Taxonomy Menu Block
This module allows to create a menu out of your taxonomies and comes with its own theme function
and a few hooks (see the .api.php file) that allows you to alter the generated data to your needs.
One of these hooks will be used by this solution.
In genereal there are four steps of this solution:
- Install the Taxonomy Menu block module if needed.
- Change the taxonomy term path of specific terms depending on their depth.
- Create appropriate aliases or update them if they are already exist.
- Set the new taxonomy term path for a specific view display.
Step by step
Install the Taxonomy Menu Block and go to: admin/structure/block/add-taxonomy-menu-block
, do some settings and save it.
Change the taxonomy term path of specific terms depending on their depth.
Here I'm looking for parents only. If they're exist, that means the term is a child.
Otherwise, it is a parent.
function YOUR_MODULE_entity_info_alter(&$entity_info) {
$entity_info['taxonomy_term']['uri callback'] = 'YOUR_MODULE_taxonomy_term_uri';
}
function YOUR_MODULE_taxonomy_term_uri($term) {
switch ($term->vocabulary_machine_name) {
case 'YOUR_VOCABULARY_MASHINE_NAME':
$parents = taxonomy_get_parents($term->tid);
if (empty($parents)) {
return array(
'path' => 'taxonomy/category/' . $term->tid,
);
}
else {
return array(
'path' => 'taxonomy/subcategory/' . $term->tid,
);
}
break;
}
// default taxonomy term uri
return taxonomy_term_uri($term);
}
Create appropriate aliases or update them if they are already exist.
Go to: admin/config/search/path/patterns
and set the pattern for all your vocabulary paths: [term:vocabulary]/[term:parents:join-path]/[term:name]
Important: If you already had pathauto running before having this issue you must rebuild the aliases by going to the delete aliases
tab and deleting the old aliases for "Taxonomy term paths", then go to the bulk update
tab and updating the "Taxonomy term paths".
Alter taxonomy menu block links
Unfortunatelly, if we change the default taxonomy term path, then neither menu created by the Taxonomy menu nor the Taxonomy Menu Block (TMB) module won't be able to replace system paths by their aliases, but luckily, the TMB allows us to alter the links to our needs:
function YOUR_MODULE_taxonomy_menu_block_tree_alter(&$tree, $vid) {
$vocabulary = taxonomy_vocabulary_load($vid);
if ($vocabulary->name == 'YOUR_VOCABULARY_MASHINE_NAME') {
foreach ($tree as $tid => $term) {
switch ($term['depth']) {
case 0 :
$tree[$tid]['path'] = drupal_get_path_alias('taxonomy/category/' . $tid);
break;
case 1 :
$tree[$tid]['path'] = drupal_get_path_alias('taxonomy/subcategory/' . $tid);
break;
}
}
}
}
View page settings
In order to use different view display for a specific term depth you need to set the appropriate path under "Page Settings" for each display. For example:
View displays:
Main category page -> path: taxonomy/category/%
Subcategory page -> path: taxonomy/subcategory/%
Notice: you can't use taxonomy/term/%
path any more, because now these specific terms have their own paths.
That's it!
In this solution both parent and child terms have their own view displays, so now you can add some new content and associate new terms to it using the simple hierarchical select only.
builtin Views taxonomy override view