protected ResourceRoutes::getRoutesForResourceConfig(RestResourceConfigInterface $rest_resource_config)
Provides all routes for a given REST resource config.
This method determines where a resource is reachable, what path replacements are used, the required HTTP method for the operation etc.
Parameters
\Drupal\rest\RestResourceConfigInterface $rest_resource_config: The rest resource config.
Return value
\Symfony\Component\Routing\RouteCollection The route collection.
File
- core/modules/rest/src/Routing/ResourceRoutes.php, line 84
Class
- ResourceRoutes
- Subscriber for REST-style routes.
Namespace
Drupal\rest\Routing
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 38 39 40 41 | protected function getRoutesForResourceConfig(RestResourceConfigInterface $rest_resource_config ) { $plugin = $rest_resource_config ->getResourcePlugin(); $collection = new RouteCollection(); foreach ( $plugin ->routes() as $name => $route ) { /** @var \Symfony\Component\Routing\Route $route */ // @todo: Are multiple methods possible here? $methods = $route ->getMethods(); // Only expose routes where the method is enabled in the configuration. if ( $methods && ( $method = $methods [0]) && $supported_formats = $rest_resource_config ->getFormats( $method )) { $route ->setRequirement( '_csrf_request_header_token' , 'TRUE' ); // Check that authentication providers are defined. if ( empty ( $rest_resource_config ->getAuthenticationProviders( $method ))) { $this ->logger->error( 'At least one authentication provider must be defined for resource @id' , array ( ':id' => $rest_resource_config ->id())); continue ; } // Check that formats are defined. if ( empty ( $rest_resource_config ->getFormats( $method ))) { $this ->logger->error( 'At least one format must be defined for resource @id' , array ( ':id' => $rest_resource_config ->id())); continue ; } // If the route has a format requirement, then verify that the // resource has it. $format_requirement = $route ->getRequirement( '_format' ); if ( $format_requirement && !in_array( $format_requirement , $rest_resource_config ->getFormats( $method ))) { continue ; } // The configuration seems legit at this point, so we set the // authentication provider and add the route. $route ->setOption( '_auth' , $rest_resource_config ->getAuthenticationProviders( $method )); $route ->setDefault( '_rest_resource_config' , $rest_resource_config ->id()); $collection ->add( "rest.$name" , $route ); } } return $collection ; } |
Please login to continue.