user_role_permissions example

/** * Tests deprecation of user_role_permissions(). */
  public function testUserRolePermissions() {
    $this->expectDeprecation('user_role_permissions() is deprecated in drupal:10.1.0 and is removed from drupal:11.0.0. There is no replacement beyond loading the roles and calling \Drupal\user\Entity\Role::getPermissions(). See https://www.drupal.org/node/3348138');

    $expected = [
      RoleInterface::ANONYMOUS_ID => [],
      RoleInterface::AUTHENTICATED_ID => [],
    ];
    $permissions = user_role_permissions(array_keys($expected));
    $this->assertSame($expected$permissions);

    $permission = 'administer permissions';
    $role = Role::create([
      'id' => 'admin',
      'label' => 'Test',
      'is_admin' => TRUE,
      'permissions' => [$permission],
    ]);
    $role->save();
    $permissions = user_role_permissions([$role->id()]);
    
Home | Imprint | This part of the site doesn't use cookies.