protected EntityResolverManager::setParametersFromReflection($controller, Route $route)
Sets the upcasting information using reflection.
Parameters
string|array $controller: A PHP callable representing the controller.
\Symfony\Component\Routing\Route $route: The route object to populate without upcasting information.
Return value
bool Returns TRUE if the upcasting parameters could be set, FALSE otherwise.
File
- core/lib/Drupal/Core/Entity/EntityResolverManager.php, line 115
Class
- EntityResolverManager
- Sets the entity route parameter converter options automatically.
Namespace
Drupal\Core\Entity
Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | protected function setParametersFromReflection( $controller , Route $route ) { $entity_types = $this ->getEntityTypes(); $parameter_definitions = $route ->getOption( 'parameters' ) ? : array (); $result = FALSE; if ( is_array ( $controller )) { list( $instance , $method ) = $controller ; $reflection = new \ReflectionMethod( $instance , $method ); } else { $reflection = new \ReflectionFunction( $controller ); } $parameters = $reflection ->getParameters(); foreach ( $parameters as $parameter ) { $parameter_name = $parameter ->getName(); // If the parameter name matches with an entity type try to set the // upcasting information automatically. Therefore take into account that // the user has specified some interface, so the upcasting is intended. if (isset( $entity_types [ $parameter_name ])) { $entity_type = $entity_types [ $parameter_name ]; $entity_class = $entity_type ->getClass(); if (( $reflection_class = $parameter ->getClass()) && ( is_subclass_of ( $entity_class , $reflection_class ->name) || $entity_class == $reflection_class ->name)) { $parameter_definitions += array ( $parameter_name => array ()); $parameter_definitions [ $parameter_name ] += array ( 'type' => 'entity:' . $parameter_name , ); $result = TRUE; } } } if (! empty ( $parameter_definitions )) { $route ->setOption( 'parameters' , $parameter_definitions ); } return $result ; } |
Please login to continue.