class BarAlterAccessPolicy

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

A test access policy that adds a permission if another permission exists.

Hierarchy

Expanded class hierarchy of BarAlterAccessPolicy

File

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

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


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