protected function EntityResolverManager::setParametersFromEntityInformation

protected EntityResolverManager::setParametersFromEntityInformation(Route $route)

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.

File

core/lib/Drupal/Core/Entity/EntityResolverManager.php, line 161

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

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Entity!EntityResolverManager.php/function/EntityResolverManager::setParametersFromEntityInformation/8.1.x