You are here

function _term_reference_tree_flatten in Taxonomy Term Reference Tree Widget 8

Same name and namespace in other branches
  1. 7.2 term_reference_tree.module \_term_reference_tree_flatten()
  2. 7 term_reference_tree.module \_term_reference_tree_flatten()

Recursively go through the option tree and return a flat array of options.

1 call to _term_reference_tree_flatten()
TermReferenceTree::validateTermReferenceTreeElement in src/Plugin/Field/FieldWidget/TermReferenceTree.php
Form element validation handler for term reference form widget.

File

./term_reference_tree.module, line 264

Code

function _term_reference_tree_flatten($element, &$form_state) {
  $output = [];
  $children = Element::children($element);
  foreach ($children as $c) {
    $child = $element[$c];
    if (array_key_exists('#type', $child) && ($child['#type'] == 'radio' || $child['#type'] == 'checkbox')) {
      $output[] = $child;
    }
    else {
      $output = array_merge($output, _term_reference_tree_flatten($child, $form_state));
    }
  }
  return $output;
}