public function EntityConverter::convert in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/lib/Drupal/Core/ParamConverter/EntityConverter.php \Drupal\Core\ParamConverter\EntityConverter::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
2 calls to EntityConverter::convert()
- AdminPathConfigEntityConverter::convert in core/
lib/ Drupal/ Core/ ParamConverter/ AdminPathConfigEntityConverter.php - Converts path variables to their corresponding objects.
- ViewUIConverter::convert in core/
modules/ views_ui/ src/ ParamConverter/ ViewUIConverter.php - Converts path variables to their corresponding objects.
2 methods override EntityConverter::convert()
- AdminPathConfigEntityConverter::convert in core/
lib/ Drupal/ Core/ ParamConverter/ AdminPathConfigEntityConverter.php - Converts path variables to their corresponding objects.
- ViewUIConverter::convert in core/
modules/ views_ui/ src/ ParamConverter/ ViewUIConverter.php - Converts path variables to their corresponding objects.
File
- core/
lib/ Drupal/ Core/ ParamConverter/ EntityConverter.php, line 66 - Contains \Drupal\Core\ParamConverter\EntityConverter.
Class
- EntityConverter
- Parameter converter for upcasting entity IDs to full objects.
Namespace
Drupal\Core\ParamConverterCode
public function convert($value, $definition, $name, array $defaults) {
$entity_type_id = $this
->getEntityTypeFromDefaults($definition, $name, $defaults);
if ($storage = $this->entityManager
->getStorage($entity_type_id)) {
$entity = $storage
->load($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->entityManager
->getTranslationFromContext($entity, NULL, array(
'operation' => 'entity_upcast',
));
}
return $entity;
}
}