diff --git a/src/Element/CheckboxTree.php b/src/Element/CheckboxTree.php index 2823a61..fdd3647 100644 --- a/src/Element/CheckboxTree.php +++ b/src/Element/CheckboxTree.php @@ -38,7 +38,7 @@ class CheckboxTree extends FormElement { */ public static function processCheckboxes(&$element, FormStateInterface $form_state, &$complete_form) { $value = is_array($element['#value']) ? $element['#value'] : []; - $allowed = ''; + $allowed = []; if (!empty($element['#max_choices']) && $element['#max_choices'] != '-1') { $element['#attached']['drupalSettings'] = [ 'term_reference_tree' => [ @@ -54,7 +54,8 @@ class CheckboxTree extends FormElement { if (empty($element['#options'])) { $options_tree = []; foreach ($element['#vocabularies'] as $vocabulary) { - $options_tree += _term_reference_tree_get_term_hierarchy(0, $vocabulary->id(), $allowed, '', '', $value); + $options = _term_reference_tree_get_term_hierarchy(0, $vocabulary->id(), $allowed, '', '', $value); + $options_tree = array_merge($options_tree, $options); } $element['#options_tree'] = $options_tree; $element['#options'] = _term_reference_tree_get_options($element['#options_tree'], $allowed, NULL); diff --git a/term_reference_tree.module b/term_reference_tree.module index aaf27b3..8101eac 100644 --- a/term_reference_tree.module +++ b/term_reference_tree.module @@ -136,7 +136,7 @@ function theme_checkbox_tree_label($variables) { function _term_reference_tree_get_term_hierarchy($tid, $vid, &$allowed, $filter, $label, $default = array()) { $terms = _term_reference_tree_get_children($tid, $vid); - $result = array(); + $result = []; if ($filter != '') { foreach ($allowed as $k => $v) { @@ -208,7 +208,6 @@ function _term_reference_tree_get_children($tid, $vid) { while ($term = $results->fetchObject()) { $terms[$term->tid] = $term; } - return $terms; } @@ -221,17 +220,6 @@ function _term_reference_tree_children_selected($terms, $default) { return FALSE; } -function _term_reference_tree_get_parent($tid) { - $q = db_query_range("SELECT h.parent FROM {taxonomy_term_hierarchy} h WHERE h.tid = :tid", 0, 1, array(':tid' => $tid)); - - $t = 0; - foreach ($q as $term) { - $t = $term->parent; - } - - return $t; -} - /** * Recursively go through the option tree and return a flat array of * options