function role_expire_form_user_role_form_alter in Role Expire 2.x
Same name and namespace in other branches
- 8 role_expire.module \role_expire_form_user_role_form_alter()
Implements hook_form_FORM_ID_alter().
Add role default duration field to role edit form.
File
- ./
role_expire.module, line 35 - Role Expire module.
Code
function role_expire_form_user_role_form_alter(&$form, FormStateInterface $form_state) {
if (\Drupal::currentUser()
->hasPermission('edit role expire default duration') || \Drupal::currentUser()
->hasPermission('administer users')) {
$formatted_link = new FormattableMarkup('<a href="@link" target="_blank">strtotime</a>', [
'@link' => 'http://php.net/manual/en/function.strtotime.php',
]);
$form['role_expire'] = [
'#title' => t("Default duration for the role %role", [
'%role' => ucfirst($form['label']['#default_value']),
]),
'#type' => 'textfield',
'#size' => 30,
'#default_value' => \Drupal::service('role_expire.api')
->getDefaultDuration($form['id']['#default_value']),
'#maxlength' => 32,
'#attributes' => [
'class' => [
'role-expire-role-expiry',
],
],
'#description' => t('Enter the time span you want to set as the default duration for this role. Examples: 12 hours, 1 day, 3 days, 4 weeks, 3 months, 1 year. Leave blank for no default duration. (If you speak php, this value may be any @link-compatible relative form.)', [
'@link' => $formatted_link,
]),
];
$form['#validate'][] = 'role_expire_user_admin_role_validate';
$form['actions']['submit']['#submit'][] = 'role_expire_user_admin_role_submit';
$form['actions']['delete']['#submit'][] = 'role_expire_user_admin_role_submit_delete';
}
}