本文整理匯總了PHP中Drupal\user\UserInterface::removeRole方法的典型用法代碼示例。如果您正苦於以下問題:PHP UserInterface::removeRole方法的具體用法?PHP UserInterface::removeRole怎麽用?PHP UserInterface::removeRole使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Drupal\user\UserInterface
的用法示例。
在下文中一共展示了UserInterface::removeRole方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: doExecute
/**
* Remove role from a user.
*
* @param \Drupal\user\UserInterface $account
* User object the roles should be removed from.
* @param \Drupal\user\RoleInterface[] $roles
* Array of user roles.
*/
protected function doExecute(UserInterface $account, array $roles)
{
foreach ($roles as $role) {
// Check if user has role.
if ($account->hasRole($role->id())) {
// If you try to add anonymous or authenticated role to user, Drupal
// will throw an \InvalidArgumentException. Anonymous or authenticated
// role ID must not be assigned manually.
$account->removeRole($role->id());
// Set flag that indicates if the entity should be auto-saved later.
$this->saveLater = TRUE;
}
}
}
示例2: removeRole
/**
* {@inheritdoc}
*/
public function removeRole($rid)
{
$this->subject->removeRole($rid);
}