Same name and namespace in other branches
  1. 8.9.x core/lib/Drupal/Core/TypedData/TypedData.php \Drupal\Core\TypedData\TypedData::getRoot()
  2. 9 core/lib/Drupal/Core/TypedData/TypedData.php \Drupal\Core\TypedData\TypedData::getRoot()

Returns the root of the typed data tree.

Returns the root data for a tree of typed data objects; e.g. for an entity field item the root of the tree is its parent entity object.

Return value

\Drupal\Core\TypedData\TraversableTypedDataInterface The root data structure, either complex data or a list.

Overrides TypedDataInterface::getRoot

File

core/lib/Drupal/Core/TypedData/TypedData.php, line 162

Class

TypedData
The abstract base class for typed data.

Namespace

Drupal\Core\TypedData

Code

public function getRoot() {
  if (isset($this->parent)) {
    return $this->parent
      ->getRoot();
  }

  // If no parent is set, this is the root of the data tree.
  return $this;
}