You are here

public static function GlobalLinkTranslatorUi::validateDueDate in GlobalLink Connect for Drupal 8

Same name and namespace in other branches
  1. 8.2 src/GlobalLinkTranslatorUi.php \Drupal\globallink\GlobalLinkTranslatorUi::validateDueDate()

Validate that the due date is in the future.

Parameters

array $element: The input element to validate.

\Drupal\Core\Form\FormStateInterface $form_state: The form state.

File

src/GlobalLinkTranslatorUi.php, line 377
Contains Drupal\globallink\GlobalLinkTranslatorUi.

Class

GlobalLinkTranslatorUi
GlobalLink translator UI.

Namespace

Drupal\globallink

Code

public static function validateDueDate(array $element, FormStateInterface &$form_state) {
  $current_date = new DrupalDateTime();
  if (isset($element['#value']['object'])) {
    $due_date = $element['#value']['object'];
    if ($due_date <= $current_date) {
      $form_state
        ->setError($element, t('Due date must be in the future.'));
    }
  }
  else {
    $form_state
      ->setError($element, t('Due date is invalid. Please enter in yyyy-mm-dd format or select from calendar'));
  }
}