public function EntityAdapter::get in Zircon Profile 8.0
Same name and namespace in other branches
- 8 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
File
- core/
lib/ Drupal/ Core/ Entity/ Plugin/ DataType/ EntityAdapter.php, line 81 - Contains \Drupal\Core\Entity\Plugin\DataType\EntityAdapter.
Class
- EntityAdapter
- Defines the "entity" data type.
Namespace
Drupal\Core\Entity\Plugin\DataTypeCode
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) {
// @todo: Add support for config entities in
// https://www.drupal.org/node/1818574.
throw new \InvalidArgumentException("Unable to get unknown property {$property_name}.");
}
// This will throw an exception for unknown fields.
return $this->entity
->get($property_name);
}