function TypedDataManagerInterface::getCanonicalRepresentation
Same name in other branches
- 9 core/lib/Drupal/Core/TypedData/TypedDataManagerInterface.php \Drupal\Core\TypedData\TypedDataManagerInterface::getCanonicalRepresentation()
- 8.9.x core/lib/Drupal/Core/TypedData/TypedDataManagerInterface.php \Drupal\Core\TypedData\TypedDataManagerInterface::getCanonicalRepresentation()
- 11.x core/lib/Drupal/Core/TypedData/TypedDataManagerInterface.php \Drupal\Core\TypedData\TypedDataManagerInterface::getCanonicalRepresentation()
Gets the canonical representation of a TypedData object.
The canonical representation is typically used when data is passed on to other code components. In many use cases, the TypedData object is mostly unified adapter wrapping a primary value (a string, an entity, etc.) which is the canonical representation that consuming code like constraint validators are really interested in. For some APIs, though, the domain object (for example, Field API's FieldItem and FieldItemList) directly implements TypedDataInterface, and the canonical representation is thus the data object itself.
When a TypedData object gets validated, for example, its canonical representation is passed on to constraint validators, which thus receive an Entity unwrapped, but a FieldItem as is.
Data types specify whether their data objects need unwrapping by using the 'unwrap_for_canonical_representation' property in the data definition (defaults to TRUE).
Parameters
\Drupal\Core\TypedData\TypedDataInterface $data: The data.
Return value
mixed The canonical representation of the passed data.
File
-
core/
lib/ Drupal/ Core/ TypedData/ TypedDataManagerInterface.php, line 245
Class
- TypedDataManagerInterface
- Defines an interface for typed data manager.
Namespace
Drupal\Core\TypedDataCode
public function getCanonicalRepresentation(TypedDataInterface $data);
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.