You are here

public static function TermReferenceFancytree::getSelectedAncestors in Term Reference Fancytree 8

Same name and namespace in other branches
  1. 8.2 src/Element/TermReferenceFancytree.php \Drupal\term_reference_fancytree\Element\TermReferenceFancytree::getSelectedAncestors()

Function that goes through the default values and obtains their ancestors.

Parameters

array $values: The selected items.

Return value

array The list of ancestors.

1 call to TermReferenceFancytree::getSelectedAncestors()
TermReferenceFancytree::processTree in src/Element/TermReferenceFancytree.php

File

src/Element/TermReferenceFancytree.php, line 80

Class

TermReferenceFancytree
Term Reference Tree Form Element.

Namespace

Drupal\term_reference_fancytree\Element

Code

public static function getSelectedAncestors(array $values, $processing_input) {
  $all_ancestors = [];
  foreach ($values as $value) {

    // Check if we are processing input or not because the structure of
    // default values and form state differs.
    if (!$processing_input) {
      $value = $value['target_id'];
    }
    $term_ancestors = \Drupal::entityTypeManager()
      ->getStorage('taxonomy_term')
      ->loadAllParents($value);
    foreach ($term_ancestors as $ancestor) {
      $all_ancestors[$ancestor
        ->id()] = $ancestor;
    }
  }
  return $all_ancestors;
}