function DynamicEntityTypeParamConverterTrait::getEntityTypeFromDefaults
Same name in other branches
- 9 core/lib/Drupal/Core/ParamConverter/DynamicEntityTypeParamConverterTrait.php \Drupal\Core\ParamConverter\DynamicEntityTypeParamConverterTrait::getEntityTypeFromDefaults()
- 8.9.x core/lib/Drupal/Core/ParamConverter/DynamicEntityTypeParamConverterTrait.php \Drupal\Core\ParamConverter\DynamicEntityTypeParamConverterTrait::getEntityTypeFromDefaults()
- 10 core/lib/Drupal/Core/ParamConverter/DynamicEntityTypeParamConverterTrait.php \Drupal\Core\ParamConverter\DynamicEntityTypeParamConverterTrait::getEntityTypeFromDefaults()
Determines the entity type ID given a route definition and route defaults.
Parameters
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
string The entity type ID.
Throws
\Drupal\Core\ParamConverter\ParamNotConvertedException Thrown when the dynamic entity type is not found in the route defaults.
4 calls to DynamicEntityTypeParamConverterTrait::getEntityTypeFromDefaults()
- AdminPathConfigEntityConverter::convert in core/
lib/ Drupal/ Core/ ParamConverter/ AdminPathConfigEntityConverter.php - Converts path variables to their corresponding objects.
- EntityConverter::convert in core/
lib/ Drupal/ Core/ ParamConverter/ EntityConverter.php - Converts path variables to their corresponding objects.
- EntityRevisionParamConverter::convert in core/
lib/ Drupal/ Core/ ParamConverter/ EntityRevisionParamConverter.php - Converts path variables to their corresponding objects.
- EntityUuidConverter::convert in core/
modules/ jsonapi/ src/ ParamConverter/ EntityUuidConverter.php - Converts path variables to their corresponding objects.
File
-
core/
lib/ Drupal/ Core/ ParamConverter/ DynamicEntityTypeParamConverterTrait.php, line 26
Class
- DynamicEntityTypeParamConverterTrait
- Provides a trait to replace dynamic entity types in routes.
Namespace
Drupal\Core\ParamConverterCode
protected function getEntityTypeFromDefaults($definition, $name, array $defaults) {
$type_part = strstr($definition['type'], ':');
if (!$type_part) {
throw new ParamNotConvertedException(sprintf('The type definition "%s" is invalid. The expected format is "entity_revision:<entity_type_id>".', $definition['type']));
}
$entity_type_id = substr($type_part, 1);
// If the entity type is dynamic, it will be pulled from the route defaults.
if (str_starts_with($entity_type_id, '{')) {
$entity_type_slug = substr($entity_type_id, 1, -1);
if (!isset($defaults[$entity_type_slug])) {
throw new ParamNotConvertedException(sprintf('The "%s" parameter was not converted because the "%s" parameter is missing.', $name, $entity_type_slug));
}
$entity_type_id = $defaults[$entity_type_slug];
}
return $entity_type_id;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.