You are here

protected function EntityResolverManager::setParametersFromEntityInformation in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/lib/Drupal/Core/Entity/EntityResolverManager.php \Drupal\Core\Entity\EntityResolverManager::setParametersFromEntityInformation()

Sets the upcasting information using the _entity_* route defaults.

Supports the '_entity_view' and '_entity_form' route defaults.

Parameters

\Symfony\Component\Routing\Route $route: The route object.

1 call to EntityResolverManager::setParametersFromEntityInformation()
EntityResolverManager::setRouteOptions in core/lib/Drupal/Core/Entity/EntityResolverManager.php
Set the upcasting route objects.

File

core/lib/Drupal/Core/Entity/EntityResolverManager.php, line 166
Contains \Drupal\Core\Entity\EntityResolverManager.

Class

EntityResolverManager
Sets the entity route parameter converter options automatically.

Namespace

Drupal\Core\Entity

Code

protected function setParametersFromEntityInformation(Route $route) {
  if ($entity_view = $route
    ->getDefault('_entity_view')) {
    list($entity_type) = explode('.', $entity_view, 2);
  }
  elseif ($entity_form = $route
    ->getDefault('_entity_form')) {
    list($entity_type) = explode('.', $entity_form, 2);
  }
  if (isset($entity_type) && isset($this
    ->getEntityTypes()[$entity_type])) {
    $parameter_definitions = $route
      ->getOption('parameters') ?: array();

    // First try to figure out whether there is already a parameter upcasting
    // the same entity type already.
    foreach ($parameter_definitions as $info) {
      if (isset($info['type'])) {

        // The parameter types are in the form 'entity:$entity_type'.
        list(, $parameter_entity_type) = explode(':', $info['type'], 2);
        if ($parameter_entity_type == $entity_type) {
          return;
        }
      }
    }
    if (!isset($parameter_definitions[$entity_type])) {
      $parameter_definitions[$entity_type] = array();
    }
    $parameter_definitions[$entity_type] += array(
      'type' => 'entity:' . $entity_type,
    );
    if (!empty($parameter_definitions)) {
      $route
        ->setOption('parameters', $parameter_definitions);
    }
  }
}