You are here

public function EntityConverter::applies in Drupal 8

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/ParamConverter/EntityConverter.php \Drupal\Core\ParamConverter\EntityConverter::applies()

Determines if the converter applies to a specific route and variable.

Parameters

mixed $definition: The parameter definition provided in the route options.

string $name: The name of the parameter.

\Symfony\Component\Routing\Route $route: The route to consider attaching to.

Return value

bool TRUE if the converter applies to the passed route and parameter, FALSE otherwise.

Overrides ParamConverterInterface::applies

1 call to EntityConverter::applies()
AdminPathConfigEntityConverter::applies in core/lib/Drupal/Core/ParamConverter/AdminPathConfigEntityConverter.php
Determines if the converter applies to a specific route and variable.
2 methods override EntityConverter::applies()
AdminPathConfigEntityConverter::applies in core/lib/Drupal/Core/ParamConverter/AdminPathConfigEntityConverter.php
Determines if the converter applies to a specific route and variable.
EntityUuidConverter::applies in core/modules/jsonapi/src/ParamConverter/EntityUuidConverter.php
Determines if the converter applies to a specific route and variable.

File

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

Class

EntityConverter
Parameter converter for upcasting entity IDs to full objects.

Namespace

Drupal\Core\ParamConverter

Code

public function applies($definition, $name, Route $route) {
  if (!empty($definition['type']) && strpos($definition['type'], 'entity:') === 0) {
    $entity_type_id = substr($definition['type'], strlen('entity:'));
    if (strpos($definition['type'], '{') !== FALSE) {
      $entity_type_slug = substr($entity_type_id, 1, -1);
      return $name != $entity_type_slug && in_array($entity_type_slug, $route
        ->compile()
        ->getVariables(), TRUE);
    }
    return $this->entityTypeManager
      ->hasDefinition($entity_type_id);
  }
  return FALSE;
}