public function HijriDateListWidget::validate in Hijri 8.2
Same name and namespace in other branches
- 3.0.x src/Plugin/Field/FieldWidget/HijriDateListWidget.php \Drupal\hijri\Plugin\Field\FieldWidget\HijriDateListWidget::validate()
- 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 77
Class
- HijriDateListWidget
- Plugin implementation of the 'HijriDateListWidget' widget.
Namespace
Drupal\hijri\Plugin\Field\FieldWidgetCode
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'];
$correction = $field_values[0]['correction'];
// @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.'));
}
}