class EntityUuidConverter in JSON:API 8
Same name and namespace in other branches
- 8.2 src/ParamConverter/EntityUuidConverter.php \Drupal\jsonapi\ParamConverter\EntityUuidConverter
Parameter converter for upcasting entity UUIDs to full objects.
@todo Remove when https://www.drupal.org/node/2353611 lands.
@internal
Hierarchy
- class \Drupal\Core\ParamConverter\EntityConverter implements ParamConverterInterface uses DeprecatedServicePropertyTrait, DynamicEntityTypeParamConverterTrait
- class \Drupal\jsonapi\ParamConverter\EntityUuidConverter
Expanded class hierarchy of EntityUuidConverter
See also
\Drupal\Core\ParamConverter\EntityConverter
1 string reference to 'EntityUuidConverter'
1 service uses EntityUuidConverter
File
- src/
ParamConverter/ EntityUuidConverter.php, line 20
Namespace
Drupal\jsonapi\ParamConverterView source
class EntityUuidConverter extends EntityConverter {
/**
* {@inheritdoc}
*/
public function convert($value, $definition, $name, array $defaults) {
$entity_type_id = $this
->getEntityTypeFromDefaults($definition, $name, $defaults);
if ($storage = $this->entityManager
->getStorage($entity_type_id)) {
if (!($entities = $storage
->loadByProperties([
'uuid' => $value,
]))) {
return NULL;
}
$entity = reset($entities);
// 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, [
'operation' => 'entity_upcast',
]);
}
return $entity;
}
return NULL;
}
/**
* {@inheritdoc}
*/
public function applies($definition, $name, Route $route) {
return (bool) Routes::getResourceTypeNameFromParameters($route
->getDefaults()) && !empty($definition['type']) && strpos($definition['type'], 'entity') === 0;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DeprecatedServicePropertyTrait:: |
public | function | Allows to access deprecated/removed properties. | |
DynamicEntityTypeParamConverterTrait:: |
protected | function | Determines the entity type ID given a route definition and route defaults. | |
EntityConverter:: |
protected | property | ||
EntityConverter:: |
protected | property | Entity repository. | |
EntityConverter:: |
protected | property | Entity type manager which performs the upcasting in the end. | |
EntityConverter:: |
protected | function | Returns the latest revision translation of the specified entity. | |
EntityConverter:: |
protected | function | Returns a language manager instance. | |
EntityConverter:: |
protected | function | Loads the specified entity revision. | |
EntityConverter:: |
public | function | Constructs a new EntityConverter. | 1 |
EntityUuidConverter:: |
public | function |
Determines if the converter applies to a specific route and variable. Overrides EntityConverter:: |
|
EntityUuidConverter:: |
public | function |
Converts path variables to their corresponding objects. Overrides EntityConverter:: |