function uc_role_delete in Ubercart 8.4
Deletes an expiration using user id or user id and rid.
This function deletes expirations associated with users and roles. If no role ID is passed, the function deletes all role expirations associated with the given user. Otherwise, the function only deletes expirations whose user and role IDs match. If any roles were actually deleted, the function notifies the user. The menu cache is then flushed, as privileges to view menu items may have been lost in the process.
Parameters
\Drupal\user\UserInterface $account: A Drupal user object.
string $rid: A Drupal role ID.
bool $silent: When set to TRUE will suppress any Drupal messages from this function.
7 calls to uc_role_delete()
- RoleDeleteForm::submitForm in uc_role/
src/ Form/ RoleDeleteForm.php - Form submission handler.
- uc_role_cron in uc_role/
uc_role.module - Implements hook_cron().
- uc_role_grant in uc_role/
uc_role.module - Grants a role to a given user.
- uc_role_renew in uc_role/
uc_role.module - Renews a given role on a user.
- uc_role_revoke in uc_role/
uc_role.module - Revokes a role on a given user.
File
- uc_role/
uc_role.module, line 482 - Grants roles upon accepted payment of products.
Code
function uc_role_delete(UserInterface $account, $rid = NULL, $silent = FALSE) {
$connection = \Drupal::database();
$query = $connection
->delete('uc_roles_expirations')
->condition('uid', $account
->id());
if ($rid) {
$query
->condition('rid', $rid);
}
// Echo the deletion only if something was actually deleted.
if ($query
->execute() && !$silent) {
if (\Drupal::currentUser()
->id() == $account
->id()) {
\Drupal::messenger()
->addMessage(t('The expiration of your %role_name role has been deleted.', [
'%role_name' => _uc_role_get_name($rid),
]));
}
else {
$username = [
'#theme' => 'username',
'#account' => $account,
];
\Drupal::messenger()
->addMessage(t('The expiration of %role_name role for the user @user has been deleted.', [
'@user' => drupal_render($username),
'%role_name' => _uc_role_get_name($rid),
]));
}
}
}