public function ResourceBase::permissions

Provides an array of permissions suitable for hook_permission().

Every plugin operation method gets its own user permission. Example: "restful delete entity:node" with the title "Access DELETE on Node resource".

@reutrn array The permission array.

File

drupal/core/modules/rest/lib/Drupal/rest/Plugin/ResourceBase.php, line 29
Definition of Drupal\rest\Plugin\ResourceBase.

Class

ResourceBase
Common base class for resource plugins.

Namespace

Drupal\rest\Plugin

Code

public function permissions() {
  $permissions = array();
  $definition = $this
    ->getDefinition();
  foreach ($this
    ->requestMethods() as $method) {
    $lowered_method = strtolower($method);

    // Only expose permissions where the HTTP request method exists on the
    // plugin.
    if (method_exists($this, $lowered_method)) {
      $permissions["restful {$lowered_method} {$this->plugin_id}"] = array(
        'title' => t('Access @method on %label resource', array(
          '@method' => $method,
          '%label' => $definition['label'],
        )),
      );
    }
  }
  return $permissions;
}