You are here

public function ConfigEntityRevisionsConverterBase::getEntityTypeFromDefaults in Config Entity Revisions 8.2

Same name and namespace in other branches
  1. 8 src/ConfigEntityRevisionsConverterBase.php \Drupal\config_entity_revisions\ConfigEntityRevisionsConverterBase::getEntityTypeFromDefaults()
  2. 1.x src/ConfigEntityRevisionsConverterBase.php \Drupal\config_entity_revisions\ConfigEntityRevisionsConverterBase::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

ParamNotConvertedException Thrown when the dynamic entity type is not found in the route defaults.

Overrides DynamicEntityTypeParamConverterTrait::getEntityTypeFromDefaults

File

src/ConfigEntityRevisionsConverterBase.php, line 234

Class

ConfigEntityRevisionsConverterBase
Parameter converter for upcasting entity IDs to full objects.

Namespace

Drupal\config_entity_revisions

Code

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