You are here

public function HijriDefaultWidget::validate in Hijri 3.0.x

Same name and namespace in other branches
  1. 8.2 src/Plugin/Field/FieldWidget/HijriDefaultWidget.php \Drupal\hijri\Plugin\Field\FieldWidget\HijriDefaultWidget::validate()
  2. 1.0.x src/Plugin/Field/FieldWidget/HijriDefaultWidget.php \Drupal\hijri\Plugin\Field\FieldWidget\HijriDefaultWidget::validate()

Validate field.

File

src/Plugin/Field/FieldWidget/HijriDefaultWidget.php, line 55

Class

HijriDefaultWidget
Plugin implementation of the 'HijriDefaultWidget' widget.

Namespace

Drupal\hijri\Plugin\Field\FieldWidget

Code

public function validate(&$element, FormStateInterface &$form_state, $form) {

  // parent::validate($element, $form_state, $form);.
  // @todo Fix this issue to support more than one field.
  // @todo Get field name the right way.
  $field_name = $element['#array_parents'][0];
  $field_values = $form_state
    ->getValue([
    $field_name,
  ]);
  $value = $field_values[0]['value'];

  // We have to convert this selected date to be in iso8601.
  // @todo We have to validate the provided Hijri date.
  if ($element['#required'] || strlen($value) > 0 || strlen($value) > 0) {
    $form_state
      ->setError($element, $this
      ->t('Field is required.'));
  }
}