By dawehner on
Change record status:
Published (View all published change records)
Project:
Introduced in branch:
8.x
Issue links:
Description:
Instead of accessing the information about roles directly there are a bunch of helper methods.
Drupal 7:
// Get a list of all roles.
$account->roles
// Check whether a user has a certain role
isset($account->roles[$rid])
// Add a role
$account->roles[$rid] = $rid;
// Remove a role
unset($account->roles[$rid]);
Drupal 8
// Get a list of all roles.
$account->getRoles()
// Check whether a user has a certain role
$account->hasRole($rid);
// Add a role
$account->addRole($rid);
// Remove a role
$account->removeRole($rid);