class BarAlterAccessPolicy

Same name and namespace in other branches
  1. 10 core/tests/Drupal/Tests/Core/Session/AccessPolicyProcessorTest.php \Drupal\Tests\Core\Session\BarAlterAccessPolicy

Hierarchy

Expanded class hierarchy of BarAlterAccessPolicy

File

core/tests/Drupal/Tests/Core/Session/AccessPolicyProcessorTest.php, line 474

Namespace

Drupal\Tests\Core\Session
View source
class BarAlterAccessPolicy extends AccessPolicyBase {
    public function applies(string $scope) : bool {
        return $scope === 'bar' || $scope === 'anything';
    }
    public function alterPermissions(AccountInterface $account, string $scope, RefinableCalculatedPermissionsInterface $calculated_permissions) : void {
        parent::alterPermissions($account, $scope, $calculated_permissions);
        foreach ($calculated_permissions->getItemsByScope($scope) as $item) {
            $permissions = $item->getPermissions();
            if (($key = array_search('bar', $permissions, TRUE)) !== FALSE) {
                $permissions[$key] = 'baz';
                $new_item = new CalculatedPermissionsItem($permissions, FALSE, $item->getScope(), $item->getIdentifier());
                $calculated_permissions->addItem($new_item, TRUE);
            }
        }
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title Overrides
AccessPolicyBase::calculatePermissions public function Calculates the permissions for an account within a given scope. Overrides AccessPolicyInterface::calculatePermissions 7
AccessPolicyBase::getPersistentCacheContexts public function Gets the persistent cache contexts. Overrides AccessPolicyInterface::getPersistentCacheContexts 9
AccessPolicyInterface::SCOPE_DRUPAL constant Scope ID for general Drupal access.
BarAlterAccessPolicy::alterPermissions public function Alter the permissions after all policies have finished building them. Overrides AccessPolicyBase::alterPermissions
BarAlterAccessPolicy::applies public function Checks whether this access policy applies to a given scope. Overrides AccessPolicyBase::applies

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