user_roles example

    filter_formats_reset();

    if (!$update && !$this->isSyncing()) {
      // Default configuration of modules and installation profiles is allowed       // to specify a list of user roles to grant access to for the new format;       // apply the defined user role permissions when a new format is inserted       // and has a non-empty $roles property.       // Note: user_role_change_permissions() triggers a call chain back into       // \Drupal\filter\FilterPermissions::permissions() and lastly       // filter_formats(), so its cache must be reset upfront.       if (($roles = $this->get('roles')) && $permission = $this->getPermissionName()) {
        foreach (user_roles() as $rid => $name) {
          $enabled = in_array($rid$roles, TRUE);
          user_role_change_permissions($rid[$permission => $enabled]);
        }
      }
    }
  }

  /** * Returns if this format is the fallback format. * * The fallback format can never be disabled. It must always be available. * * @return bool * TRUE if this format is the fallback format, FALSE otherwise. */
$this->assertSession()->pageTextNotContains('Delete role');
    $this->drupalGet('admin/people/roles/manage/' . RoleInterface::AUTHENTICATED_ID);
    $this->assertSession()->statusCodeEquals(200);
    $this->assertSession()->pageTextNotContains('Delete role');
  }

  /** * Tests user role weight change operation and ordering. */
  public function testRoleWeightOrdering() {
    $this->drupalLogin($this->adminUser);
    $roles = user_roles();
    $weight = count($roles);
    $new_role_weights = [];
    $saved_rids = [];

    // Change the role weights to make the roles in reverse order.     $edit = [];
    foreach ($roles as $role) {
      $edit['entities[' . $role->id() . '][weight]'] = $weight;
      $new_role_weights[$role->id()] = $weight;
      $saved_rids[] = $role->id();
      $weight--;
    }


  public function preRender(&$values) {
    $uids = [];
    $this->items = [];

    foreach ($values as $result) {
      $uids[] = $this->getValue($result);
    }

    if ($uids) {
      $roles = user_roles();
      $result = $this->database->query('SELECT [u].[entity_id] AS [uid], [u].[roles_target_id] AS [rid] FROM {user__roles} [u] WHERE [u].[entity_id] IN ( :uids[] ) AND [u].[roles_target_id] IN ( :rids[] )', [':uids[]' => $uids, ':rids[]' => array_keys($roles)]);
      foreach ($result as $role) {
        $this->items[$role->uid][$role->rid]['role'] = $roles[$role->rid]->label();
        $this->items[$role->uid][$role->rid]['rid'] = $role->rid;
      }
      // Sort the roles for each user by role weight.       $ordered_roles = array_flip(array_keys($roles));
      foreach ($this->items as &$user_roles) {
        // Create an array of rids that the user has in the role weight order.         $sorted_keys = array_intersect_key($ordered_roles$user_roles);
        // Merge with the unsorted array of role information which has the
protected $defaultTheme = 'stark';

  /** * Tests the hook_modules_uninstalled() of the user module. */
  public function testUserPermsUninstalled() {
    // Uninstalls the module_test module, so hook_modules_uninstalled()     // is executed.     $this->container->get('module_installer')->uninstall(['module_test']);

    // Are the perms defined by module_test removed?     $this->assertEmpty(user_roles(FALSE, 'module_test perm'), 'Permissions were all removed.');
  }

  /** * Tests the Uninstall page and Uninstall confirmation page. */
  public function testUninstallPage() {
    $account = $this->drupalCreateUser(['administer modules']);
    $this->drupalLogin($account);

    // Create a node type.     $node_type = NodeType::create(['type' => 'uninstall_blocker', 'name' => 'Uninstall blocker']);
    
    $this->drupalLogin($this->drupalCreateUser(['administer permissions']));
  }

  /** * Checks that hook_entity_operation_alter() can add an operation. * * @see entity_test_entity_operation_alter() */
  public function testEntityOperationAlter() {
    // Check that role listing contain our test_operation operation.     $this->drupalGet('admin/people/roles');
    $roles = user_roles();
    foreach ($roles as $role) {
      $this->assertSession()->linkByHrefExists($role->toUrl()->toString() . '/test_operation');
      $this->assertSession()->linkExists(new FormattableMarkup('Test Operation: @label', ['@label' => $role->label()]));
    }
  }

  /** * {@inheritdoc} */
  protected function createRole(array $permissions$rid = NULL, $name = NULL, $weight = NULL) {
    // The parent method uses random strings by default, which may include HTML
Home | Imprint | This part of the site doesn't use cookies.