User::addRole() does not return a value, meaning the function be changed.
Execute the following code, where $id
is an existing user ID, and $role_id
is the machine name of an existing role.
\Drupal::entityTypeManager()->getStorage('user')
->load($id)
->addRole($role_id)
->save();
An error is thrown that save() is called on NULL.
User::addRole() should return $this
.
Write tests.
None.
None needed - this is for forward compatibility.
None.
Methods User::addRole()
and User::removeRole()
previously did not return a value, and therefore could not be chained. Now both return $self
and can be used in chained calls.
Previous:
$user->removeRole('editor');
$user->addRole('contributor');
$user->save();
New:
$user
->removeRole('editor')
->addRole('contributor')
->save();
Fixed
10.1 ✨
Last updated
Not all content is available!
It's likely this issue predates Contrib.social: some issue and comment data are missing.
No activities found.