function role_expire_add_expiration_input in Role Expire 8
Same name and namespace in other branches
- 6 role_expire.module \role_expire_add_expiration_input()
- 7 role_expire.module \role_expire_add_expiration_input()
- 2.x role_expire.module \role_expire_add_expiration_input()
Add form element that accepts the role expiration time.
Parameters
\Drupal\user\Entity\User $account: Edited user or null.
Return value
array Form element.
1 call to role_expire_add_expiration_input()
- role_expire_form_user_form_alter in ./
role_expire.module - Implements hook_form_FORM_ID_alter().
File
- ./
role_expire.module, line 379 - Role Expire module.
Code
function role_expire_add_expiration_input($account) {
$form = [];
if (\Drupal::currentUser()
->hasPermission('administer users') || \Drupal::currentUser()
->hasPermission('administer role expire')) {
$form['#attached']['library'][] = 'role_expire/role_expire';
$form['roles']['#attributes'] = [
'class' => [
'role-expire-roles',
],
];
foreach (_role_expire_get_role() as $rid => $role) {
if (!is_null($account)) {
$expiry_timestamp = \Drupal::service('role_expire.api')
->getUserRoleExpiryTime($account
->id(), $rid);
}
else {
$expiry_timestamp = '';
}
$form['role_expire_' . $rid] = [
'#title' => t("%role role expiration date/time", [
'%role' => $role,
]),
'#type' => 'textfield',
'#default_value' => !empty($expiry_timestamp) ? date("Y-m-d H:i:s", $expiry_timestamp) : '',
'#attributes' => [
'class' => [
'role-expire-role-expiry',
],
],
'#description' => t("Leave blank for default role expiry (never, or the duration you have set for the role), enter date and time in format: <em>yyyy-mm-dd hh:mm:ss</em> or use relative time i.e. 1 day, 2 months, 1 year, 3 years."),
];
}
$form['#validate'][] = '_role_expire_validate_role_expires';
}
return $form;
}