AccessResultForbidden.php

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

Namespace

Drupal\Core\Access

File

core/lib/Drupal/Core/Access/AccessResultForbidden.php

View source
<?php

namespace Drupal\Core\Access;


/**
 * Value object indicating a forbidden access result, with cacheability metadata.
 */
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;
    }

}

Classes

Title Deprecated Summary
AccessResultForbidden Value object indicating a forbidden access result, with cacheability metadata.

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