You are here

protected function ResourceBase::getBaseRouteRequirements in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/rest/src/Plugin/ResourceBase.php \Drupal\rest\Plugin\ResourceBase::getBaseRouteRequirements()
  2. 9 core/modules/rest/src/Plugin/ResourceBase.php \Drupal\rest\Plugin\ResourceBase::getBaseRouteRequirements()

Gets the base route requirements for a particular method.

Parameters

$method: The HTTP method to be used for the route.

Return value

array An array of requirements for parameters.

1 call to ResourceBase::getBaseRouteRequirements()
ResourceBase::getBaseRoute in core/modules/rest/src/Plugin/ResourceBase.php
Gets the base route for a particular method.
1 method overrides ResourceBase::getBaseRouteRequirements()
FileUploadResource::getBaseRouteRequirements in core/modules/file/src/Plugin/rest/resource/FileUploadResource.php
Gets the base route requirements for a particular method.

File

core/modules/rest/src/Plugin/ResourceBase.php, line 193

Class

ResourceBase
Common base class for resource plugins.

Namespace

Drupal\rest\Plugin

Code

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
  // inaccessible. So, we default to granting access to everyone. If a
  // 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 = [
    '_access' => 'TRUE',
  ];

  // Only specify route requirements if the default permission exists. For any
  // more advanced route definition, resource plugins extending this base
  // class must override this method.
  $permission = "restful {$lower_method} {$this->pluginId}";
  if (isset($this
    ->permissions()[$permission])) {
    $requirements['_permission'] = $permission;
  }
  return $requirements;
}