function TypedDataManagerInterface::getPropertyInstance

Same name in other branches
  1. 8.9.x core/lib/Drupal/Core/TypedData/TypedDataManagerInterface.php \Drupal\Core\TypedData\TypedDataManagerInterface::getPropertyInstance()
  2. 10 core/lib/Drupal/Core/TypedData/TypedDataManagerInterface.php \Drupal\Core\TypedData\TypedDataManagerInterface::getPropertyInstance()
  3. 11.x core/lib/Drupal/Core/TypedData/TypedDataManagerInterface.php \Drupal\Core\TypedData\TypedDataManagerInterface::getPropertyInstance()

Get a typed data instance for a property of a given typed data object.

This method will use prototyping for fast and efficient instantiation of many property objects with the same property path; for example, when multiple comments are used comment_body.0.value needs to be instantiated very often.

Prototyping is done by the root object's data type and the given property path, i.e. all property instances having the same property path and inheriting from the same data type are prototyped.

Parameters

\Drupal\Core\TypedData\TypedDataInterface $object: The parent typed data object, implementing the TypedDataInterface and either the ListInterface or the ComplexDataInterface.

string $property_name: The name of the property to instantiate, or the delta of a list item.

mixed $value: (optional) The data value. If set, it has to match one of the supported data type formats as documented by the data type classes.

Return value

\Drupal\Core\TypedData\TypedDataInterface The new property instance.

Throws

\InvalidArgumentException If the given property is not known, or the passed object does not implement the ListInterface or the ComplexDataInterface.

See also

\Drupal\Core\TypedData\TypedDataManager::create()

1 method overrides TypedDataManagerInterface::getPropertyInstance()
TypedDataManager::getPropertyInstance in core/lib/Drupal/Core/TypedData/TypedDataManager.php
Get a typed data instance for a property of a given typed data object.

File

core/lib/Drupal/Core/TypedData/TypedDataManagerInterface.php, line 163

Class

TypedDataManagerInterface
Defines an interface for typed data manager.

Namespace

Drupal\Core\TypedData

Code

public function getPropertyInstance(TypedDataInterface $object, $property_name, $value = NULL);

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