function TermForm::getParentIds

Same name and namespace in other branches
  1. 9 core/modules/taxonomy/src/TermForm.php \Drupal\taxonomy\TermForm::getParentIds()
  2. 10 core/modules/taxonomy/src/TermForm.php \Drupal\taxonomy\TermForm::getParentIds()

Returns term parent IDs, including the root.

Parameters

\Drupal\taxonomy\TermInterface $term: The taxonomy term entity.

Return value

array A list if parent term IDs.

1 call to TermForm::getParentIds()
TermForm::form in core/modules/taxonomy/src/TermForm.php
Gets the actual form array to be built.

File

core/modules/taxonomy/src/TermForm.php, line 233

Class

TermForm
Base for handler for taxonomy term edit forms.

Namespace

Drupal\taxonomy

Code

protected function getParentIds(TermInterface $term) : array {
    $parent = [];
    // Get the parent directly from the term as
    // \Drupal\taxonomy\TermStorageInterface::loadParents() excludes the root.
    foreach ($term->get('parent') as $item) {
        $parent[] = (int) $item->target_id;
    }
    return $parent;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.