You are here

protected function EntityRevisionConverter::getEntityTypeFromDefaults in Workspace 8

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.

1 call to EntityRevisionConverter::getEntityTypeFromDefaults()
EntityRevisionConverter::convert in src/ParamConverter/EntityRevisionConverter.php
Converts path variables to their corresponding objects.

File

src/ParamConverter/EntityRevisionConverter.php, line 92

Class

EntityRevisionConverter
Parameter converter for upcasting entity revision IDs to full objects.

Namespace

Drupal\workspace\ParamConverter

Code

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

  // 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;
}