You are here

public function HijriDateListWidget::validate in Hijri 3.0.x

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

Validate field.

File

src/Plugin/Field/FieldWidget/HijriDateListWidget.php, line 44

Class

HijriDateListWidget
Plugin implementation of the 'HijriDateListWidget' 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'];

  // @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.'));
  }
}