class AccessResultForbidden

Same name and namespace in other branches
  1. 11.x core/lib/Drupal/Core/Access/AccessResultForbidden.php \Drupal\Core\Access\AccessResultForbidden
  2. 10 core/lib/Drupal/Core/Access/AccessResultForbidden.php \Drupal\Core\Access\AccessResultForbidden
  3. 8.9.x core/lib/Drupal/Core/Access/AccessResultForbidden.php \Drupal\Core\Access\AccessResultForbidden

Value object indicating a forbidden access result, with cacheability metadata.

Hierarchy

Expanded class hierarchy of AccessResultForbidden

4 files declare their use of AccessResultForbidden
AccessResultForbiddenTest.php in core/tests/Drupal/Tests/Core/Access/AccessResultForbiddenTest.php
book_breadcrumb_test.module in core/modules/book/tests/modules/book_breadcrumb_test/book_breadcrumb_test.module
Test module for testing the book module breadcrumb.
LatestRevisionCheckTest.php in core/modules/content_moderation/tests/src/Unit/LatestRevisionCheckTest.php
LocalActionManagerTest.php in core/tests/Drupal/Tests/Core/Menu/LocalActionManagerTest.php
Contains \Drupal\Tests\Core\Menu\LocalActionManagerTest.
2 string references to 'AccessResultForbidden'
RendererTest::testRenderWithAccessControllerResolved in core/tests/Drupal/Tests/Core/Render/RendererTest.php
@covers ::render[[api-linebreak]] @covers ::doRender[[api-linebreak]]
TestAccessClass::trustedCallbacks in core/tests/Drupal/Tests/Core/Render/RendererTest.php

File

core/lib/Drupal/Core/Access/AccessResultForbidden.php, line 8

Namespace

Drupal\Core\Access
View source
class AccessResultForbidden extends AccessResult implements AccessResultReasonInterface {
  
  /**
   * The reason why access is forbidden. For use in error messages.
   *
   * @var string
   */
  protected $reason;
  
  /**
   * Constructs a new AccessResultForbidden instance.
   *
   * @param null|string $reason
   *   (optional) A message to provide details about this access result.
   */
  public function __construct($reason = NULL) {
    $this->reason = $reason;
  }
  
  /**
   * {@inheritdoc}
   */
  public function isForbidden() {
    return TRUE;
  }
  
  /**
   * {@inheritdoc}
   */
  public function getReason() {
    return (string) $this->reason;
  }
  
  /**
   * {@inheritdoc}
   */
  public function setReason($reason) {
    $this->reason = $reason;
    return $this;
  }

}

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