You are here

protected function FieldPermissionsTestBase::getCustomPermissionGrid in Field Permissions 8

Same name and namespace in other branches
  1. 8.2 tests/src/Functional/FieldPermissionsTestBase.php \Drupal\Tests\field_permissions\Functional\FieldPermissionsTestBase::getCustomPermissionGrid()

Fill out a custom permission matrix for a given role.

Parameters

string $role: The role to grant permissions for. Other roles will not have any permissions.

array $field_perm: Permissions to grant the given role.

Return value

array The complete custom permissions matrix, keyed by {OP}_{FIELD_NAME} and then role ID, with a value of TRUE if the permission is granted, FALSE otherwise.

1 call to FieldPermissionsTestBase::getCustomPermissionGrid()
FieldPermissionsTestBase::grantCustomPermissions in tests/src/Functional/FieldPermissionsTestBase.php
Appends existing permissions grid with new permissions.

File

tests/src/Functional/FieldPermissionsTestBase.php, line 139

Class

FieldPermissionsTestBase
A base class for field permissions web tests to extend.

Namespace

Drupal\Tests\field_permissions\Functional

Code

protected function getCustomPermissionGrid($role, array $field_perm = []) {
  $custom_perm = [];
  $permission_list = $this->container
    ->get('field_permissions.permissions_service')
    ->getAllPermissions();
  $permission_list = array_keys($permission_list);
  $permission_role = array_keys(user_roles());

  // Set all check to false.
  foreach ($permission_role as $rname) {
    foreach ($permission_list as $perm) {
      $key = 'permissions[' . $perm . '][' . $rname . ']';
      $custom_perm[$key] = FALSE;
    }
  }

  // Set perm check to true.
  foreach ($field_perm as $perm) {
    $key = 'permissions[' . $perm . '][' . $role
      ->id() . ']';
    $custom_perm[$key] = TRUE;
  }
  return $custom_perm;
}