Ответы
Попробуйте
hook_shs_term_get_children_alter() и
taxonomy_select_nodes()
Пример
<?php
/**
* Alter the list of terms within a level of the term hierarchy.
*
* @param array $terms
* List of terms displayed to the user (single hierarchy level).
* @param array $alter_options
* - vid: ID of vocabulary or field name
* - parent: ID of parent term
* - settings: Additional settings (for example "language", etc.,)
*/
function YOUR_MODULE_shs_term_get_children_alter(array &$terms, array &$alter_options) {
$vid = $alter_options['vid'];
$lang = $alter_options['settings']['language']->language;
$array = &$terms[$vid][$lang];
foreach($array as &$terms) {
foreach($terms as $tid => $name) {
$child_related_with_node = FALSE;
$nodes = taxonomy_select_nodes($tid, FALSE);
if (count($nodes) != 0) {
continue;
}
else {
$children = taxonomy_get_children_all($tid, $vid);
foreach($children as $term) {
$nodes = taxonomy_select_nodes($term->tid, FALSE);
if (count($nodes) != 0) {
$child_related_with_node = TRUE;
break;
}
}
if ($child_related_with_node == FALSE) {
unset($terms[$tid]);
}
}
}
}
}
function taxonomy_get_children_all($tid, $vid){
$c = taxonomy_get_children($tid, $vid);
$result = array();
foreach ($c as $t => $d){
$result[$t] = $d;
$below = taxonomy_get_children_all($t, $vid);
if (!empty($below)) {
foreach ($below as $nt => $nd){
$result[$nt] = $nd;
}
}
}
return $result;
}
Ответ дан 17.05.2019 - 05:49