You are here

function role_expire_user_admin_role_submit in Role Expire 2.x

Same name and namespace in other branches
  1. 8 role_expire.module \role_expire_user_admin_role_submit()
  2. 6 role_expire.module \role_expire_user_admin_role_submit()
  3. 7 role_expire.module \role_expire_user_admin_role_submit()

Form submit handler invoked by role_expire_form_user_admin_role_alter.

Updates default duration in database.

1 string reference to 'role_expire_user_admin_role_submit'
role_expire_form_user_role_form_alter in ./role_expire.module
Implements hook_form_FORM_ID_alter().

File

./role_expire.module, line 103
Role Expire module.

Code

function role_expire_user_admin_role_submit($form, FormStateInterface &$form_state) {
  $values = $form_state
    ->getValues();

  /*
   * If the form doesn't specify a default duration, then delete default
   * duration. Otherwise, set the default duration to what's specified.
   */
  if (!empty($values['role_expire'])) {
    $duration_string = Html::escape($values['role_expire']);
    \Drupal::service('role_expire.api')
      ->setDefaultDuration($values['id'], $duration_string);
    \Drupal::service('messenger')
      ->addMessage('New default role expiration set.');
  }
  else {
    \Drupal::service('role_expire.api')
      ->deleteDefaultDuration($values['id']);
  }
}