availableMethods example

/** * Implements ResourceInterface::permissions(). * * Every plugin operation method gets its own user permission. Example: * "restful delete entity:node" with the title "Access DELETE on Node * resource". */
  public function permissions() {
    $permissions = [];
    $definition = $this->getPluginDefinition();
    foreach ($this->availableMethods() as $method) {
      $lowered_method = strtolower($method);
      $permissions["restful $lowered_method $this->pluginId"] = [
        'title' => $this->t('Access @method on %label resource', ['@method' => $method, '%label' => $definition['label']]),
      ];
    }
    return $permissions;
  }

  /** * {@inheritdoc} */
  
$parameters = $route->getOption('parameters') ?: [];
    $parameters[$definition['entity_type']]['type'] = 'entity:' . $definition['entity_type'];
    $route->setOption('parameters', $parameters);

    return $route;
  }

  /** * {@inheritdoc} */
  public function availableMethods() {
    $methods = parent::availableMethods();
    if ($this->isConfigEntityResource()) {
      // Currently only GET is supported for Config Entities.       // @todo Remove when supported https://www.drupal.org/node/2300677       $unsupported_methods = ['POST', 'PUT', 'DELETE', 'PATCH'];
      $methods = array_diff($methods$unsupported_methods);
    }
    return $methods;
  }

  /** * Checks if this resource is for a Config Entity. * * @return bool * TRUE if the entity is a Config Entity, FALSE otherwise. */
Home | Imprint | This part of the site doesn't use cookies.