You are here

function _role_expire_validate_role_expires in Role Expire 2.x

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

Form validation handler for the role expiration on the user_profile_form().

Helper function.

See also

user_profile_form()

1 string reference to '_role_expire_validate_role_expires'
role_expire_add_expiration_input in ./role_expire.module
Add form element that accepts the role expiration time.

File

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

Code

function _role_expire_validate_role_expires(&$form, FormStateInterface &$form_state) {
  $values = $form_state
    ->getValues();
  date_default_timezone_set(date_default_timezone_get());
  $time = \Drupal::time()
    ->getRequestTime();
  foreach ($values as $name => $value) {
    if (strpos($name, 'role_expire_') === 0 && trim($value) != '') {
      $expiry_time = strtotime($value);
      if (!$expiry_time) {
        $form_state
          ->setErrorByName($name, t("Role expiry is not in correct format."));
      }
      if ($expiry_time <= $time) {
        $form_state
          ->setErrorByName($name, t("Role expiry must be in the future."));
      }
    }
  }
}