You are here

protected static function RouterPathTranslatorSubscriber::getEntityRouteParameterName in Decoupled Router 8

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

Computes the name of the entity route parameter for JSON API routes.

@todo Remove this once decoupled_router requires jsonapi >= 8.x-2.0.

Parameters

string $route_name: A JSON API route name.

string $entity_type_id: The corresponding entity type ID.

Return value

string Either 'entity' or $entity_type_id.

File

src/EventSubscriber/RouterPathTranslatorSubscriber.php, line 300

Class

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

Namespace

Drupal\decoupled_router\EventSubscriber

Code

protected static function getEntityRouteParameterName($route_name, $entity_type_id) {
  static $first;
  if (!isset($first)) {
    $route_parameters = \Drupal::service('router.route_provider')
      ->getRouteByName($route_name)
      ->getOption('parameters');
    $first = isset($route_parameters['entity']) ? 'entity' : $entity_type_id;
    return $first;
  }
  return $first === 'entity' ? 'entity' : $entity_type_id;
}