EntityConverter::getEntityTypeFromDefaults

protected EntityConverter::getEntityTypeFromDefaults($definition, $name, array $defaults)

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.

File

core/lib/Drupal/Core/ParamConverter/EntityConverter.php, line 105

Class

EntityConverter
Parameter converter for upcasting entity IDs to full objects.

Namespace

Drupal\Core\ParamConverter

Code

protected function getEntityTypeFromDefaults($definition, $name, array $defaults) {
  $entity_type_id = substr($definition['type'], strlen('entity:'));

  // If the entity type is dynamic, it will be pulled from the route defaults.
  if (strpos($entity_type_id, '{') === 0) {
    $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;
}
doc_Drupal
2016-10-29 09:04:53
Comments
Leave a Comment

Please login to continue.