You are here

public function EntityAdapter::get in Drupal 8

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/Entity/Plugin/DataType/EntityAdapter.php \Drupal\Core\Entity\Plugin\DataType\EntityAdapter::get()

Gets a property object.

Parameters

$property_name: The name of the property to get; e.g., 'title' or 'name'.

Return value

\Drupal\Core\TypedData\TypedDataInterface The property object.

Throws

\InvalidArgumentException If an invalid property name is given.

\Drupal\Core\TypedData\Exception\MissingDataException If the complex data structure is unset and no property can be created.

Overrides ComplexDataInterface::get

1 method overrides EntityAdapter::get()
ConfigEntityAdapter::get in core/lib/Drupal/Core/Entity/Plugin/DataType/ConfigEntityAdapter.php
Gets a property object.

File

core/lib/Drupal/Core/Entity/Plugin/DataType/EntityAdapter.php, line 76

Class

EntityAdapter
Defines the "entity" data type.

Namespace

Drupal\Core\Entity\Plugin\DataType

Code

public function get($property_name) {
  if (!isset($this->entity)) {
    throw new MissingDataException("Unable to get property {$property_name} as no entity has been provided.");
  }
  if (!$this->entity instanceof FieldableEntityInterface) {
    throw new \InvalidArgumentException("Unable to get unknown property {$property_name}.");
  }

  // This will throw an exception for unknown fields.
  return $this->entity
    ->get($property_name);
}