public function EntityRevisionParamConverter::convert in Drupal 8
Same name and namespace in other branches
- 9 core/lib/Drupal/Core/ParamConverter/EntityRevisionParamConverter.php \Drupal\Core\ParamConverter\EntityRevisionParamConverter::convert()
Converts path variables to their corresponding objects.
Parameters
mixed $value: The raw value.
mixed $definition: The parameter definition provided in the route options.
string $name: The name of the parameter.
array $defaults: The route defaults array.
Return value
mixed|null The converted parameter value.
Overrides ParamConverterInterface::convert
File
- core/
lib/ Drupal/ Core/ ParamConverter/ EntityRevisionParamConverter.php, line 62
Class
- EntityRevisionParamConverter
- Parameter converter for upcasting entity revision IDs to full objects.
Namespace
Drupal\Core\ParamConverterCode
public function convert($value, $definition, $name, array $defaults) {
$entity_type_id = $this
->getEntityTypeFromDefaults($definition, $name, $defaults);
$entity = $this->entityTypeManager
->getStorage($entity_type_id)
->loadRevision($value);
// If the entity type is translatable, ensure we return the proper
// translation object for the current context.
if ($entity instanceof EntityInterface && $entity instanceof TranslatableInterface) {
$entity = $this->entityRepository
->getTranslationFromContext($entity, NULL, [
'operation' => 'entity_upcast',
]);
}
return $entity;
}