function EntityResource::generateFallbackAccessDeniedMessage

Same name in other branches
  1. 9 core/modules/rest/src/Plugin/rest/resource/EntityResource.php \Drupal\rest\Plugin\rest\resource\EntityResource::generateFallbackAccessDeniedMessage()
  2. 8.9.x core/modules/rest/src/Plugin/rest/resource/EntityResource.php \Drupal\rest\Plugin\rest\resource\EntityResource::generateFallbackAccessDeniedMessage()
  3. 11.x core/modules/rest/src/Plugin/rest/resource/EntityResource.php \Drupal\rest\Plugin\rest\resource\EntityResource::generateFallbackAccessDeniedMessage()

Generates a fallback access denied message, when no specific reason is set.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity object.

string $operation: The disallowed entity operation.

Return value

string The proper message to display in the AccessDeniedHttpException.

1 call to EntityResource::generateFallbackAccessDeniedMessage()
EntityResource::post in core/modules/rest/src/Plugin/rest/resource/EntityResource.php
Responds to entity POST requests and saves the new entity.

File

core/modules/rest/src/Plugin/rest/resource/EntityResource.php, line 350

Class

EntityResource
Represents entities as resources.

Namespace

Drupal\rest\Plugin\rest\resource

Code

protected function generateFallbackAccessDeniedMessage(EntityInterface $entity, $operation) {
    $message = "You are not authorized to {$operation} this {$entity->getEntityTypeId()} entity";
    if ($entity->bundle() !== $entity->getEntityTypeId()) {
        $message .= " of bundle {$entity->bundle()}";
    }
    return "{$message}.";
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.