You are here

public static function HijriDateList::valueCallback in Hijri 3.0.x

Same name and namespace in other branches
  1. 8.2 src/Element/HijriDateList.php \Drupal\hijri\Element\HijriDateList::valueCallback()
  2. 1.0.x src/Element/HijriDateList.php \Drupal\hijri\Element\HijriDateList::valueCallback()

Validates the date type to adjust 12 hour time and prevent invalid dates. If the date is valid, the date is set in the form.

Overrides Datelist::valueCallback

File

src/Element/HijriDateList.php, line 20

Class

HijriDateList
Override the datelist element.

Namespace

Drupal\hijri\Element

Code

public static function valueCallback(&$element, $input, FormStateInterface $form_state) {

  // If the input is defined.
  if ($input !== FALSE) {
    if (isset($input['year']) && $input['year'] > 0) {

      // The year value has been set.
      $return = $input;
      $date = date('c');
      $return['object'] = $date;

      // $form_state->setError($element, t('Test error.'));
      return $return;
    }
  }
  else {

    // This will be called when prepare the input for form.
  }
  return $input;
}