function BarAlterAccessPolicy::alterPermissions

Same name in other branches
  1. 10 core/tests/Drupal/Tests/Core/Session/AccessPolicyProcessorTest.php \Drupal\Tests\Core\Session\BarAlterAccessPolicy::alterPermissions()

Overrides AccessPolicyBase::alterPermissions

File

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

Class

BarAlterAccessPolicy

Namespace

Drupal\Tests\Core\Session

Code

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);
        }
    }
}

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