core/modules/rest/src/Plugin/ResourceBase.php | 44 +++++++++++++++++---------- 1 file changed, 28 insertions(+), 16 deletions(-) diff --git a/core/modules/rest/src/Plugin/ResourceBase.php b/core/modules/rest/src/Plugin/ResourceBase.php index 4e021e0..176a857 100644 --- a/core/modules/rest/src/Plugin/ResourceBase.php +++ b/core/modules/rest/src/Plugin/ResourceBase.php @@ -184,7 +184,7 @@ public function availableMethods() { } /** - * Setups the base route for all HTTP methods. + * Gets the base route for a particular method. * * @param string $canonical_path * The canonical path for the resource. @@ -195,6 +195,30 @@ public function availableMethods() { * The created base route. */ protected function getBaseRoute($canonical_path, $method) { + return new Route($canonical_path, array( + '_controller' => 'Drupal\rest\RequestHandler::handle', + // Pass the resource plugin ID along as default property. + '_plugin' => $this->pluginId, + ), + $this->getBaseRouteRequirements($method), + array(), + '', + array(), + // The HTTP method is a requirement for this route. + array($method) + ); + } + + /** + * Gets the base route requirements for a particular method. + * + * @param $method + * The HTTP method to be used for the route. + * + * @return array + * An array of requirements for parameters. + */ + protected function getBaseRouteRequirements($method) { $lower_method = strtolower($method); // Every route MUST have requirements that result in the access manager // having access checks to check. If it does not, the route is made @@ -202,9 +226,9 @@ protected function getBaseRoute($canonical_path, $method) { // permission exists, then we add that below. The access manager requires // that ALL access checks must grant access, so this still results in // correct behavior. - $requirements = array( + $requirements = [ '_access' => 'TRUE', - ); + ]; // Only specify route requirements if the default permission exists. For any // more advanced route definition, resource plugins extending this base @@ -214,19 +238,7 @@ protected function getBaseRoute($canonical_path, $method) { $requirements['_permission'] = $permission; } - $route = new Route($canonical_path, array( - '_controller' => 'Drupal\rest\RequestHandler::handle', - // Pass the resource plugin ID along as default property. - '_plugin' => $this->pluginId, - ), - $requirements, - array(), - '', - array(), - // The HTTP method is a requirement for this route. - array($method) - ); - return $route; + return $requirements; } }