You are here

protected function RouterPathTranslatorSubscriber::findEntityAndKeys in Decoupled Router 8

Same name and namespace in other branches
  1. 2.x src/EventSubscriber/RouterPathTranslatorSubscriber.php \Drupal\decoupled_router\EventSubscriber\RouterPathTranslatorSubscriber::findEntityAndKeys()

Get the underlying entity and the type of ID param enhancer for the routes.

Parameters

array $match_info: The router match info.

Return value

array The pair of \Drupal\Core\Entity\EntityInterface and bool with the underlying entity and the info weather or not it uses UUID for the param enhancement. It also returns the name of the parameter under which the entity lives in the route ('node' vs 'entity').

1 call to RouterPathTranslatorSubscriber::findEntityAndKeys()
RouterPathTranslatorSubscriber::onPathTranslation in src/EventSubscriber/RouterPathTranslatorSubscriber.php
Processes a path translation request.

File

src/EventSubscriber/RouterPathTranslatorSubscriber.php, line 252

Class

RouterPathTranslatorSubscriber
Event subscriber that processes a path translation with the router info.

Namespace

Drupal\decoupled_router\EventSubscriber

Code

protected function findEntityAndKeys(array $match_info) {
  $entity = NULL;

  /** @var \Symfony\Component\Routing\Route $route */
  $route = $match_info[RouteObjectInterface::ROUTE_OBJECT];
  $route_parameters = $route
    ->getOption('parameters');
  $route_parameter_entity_key = 'entity';
  if (!empty($match_info['entity']) && $match_info['entity'] instanceof EntityInterface) {
    $entity = $match_info['entity'];
  }
  else {
    $entity_type_id = $this
      ->findEntityTypeFromRoute($route);

    /** @var \Drupal\Core\Entity\EntityInterface $entity */

    // TODO: $match_info[$entity_type_id] is broken for JSON API 2.x routes.
    // Now it will be $match_info[$entity_type_id] for core and
    // $match_info['entity'] for JSON API :-(
    if (!empty($entity_type_id) && !empty($match_info[$entity_type_id]) && $match_info[$entity_type_id] instanceof EntityInterface) {
      $route_parameter_entity_key = $entity_type_id;
      $entity = $match_info[$entity_type_id];
    }
  }
  $param_uses_uuid = strpos($route_parameters[$route_parameter_entity_key]['converter'], 'entity_uuid') === FALSE;
  return [
    $entity,
    $param_uses_uuid,
    $route_parameter_entity_key,
  ];
}