public function VatNumberWidget::validate in VAT Number 8
Validate the fields and check if the vat number is valid.
File
- src/
Plugin/ Field/ FieldWidget/ VatNumberWidget.php, line 42
Class
- VatNumberWidget
- Plugin implementation of the 'vat_widget' widget.
Namespace
Drupal\vat_number\Plugin\Field\FieldWidgetCode
public function validate($element, FormStateInterface $form_state) {
$value = $element['#value'];
if (!empty($value)) {
// Include the VAT Controller.
$vatController = new VatNumberController($value);
// Validate VAT number.
$valid = $vatController
->check();
if (!$valid['status']) {
$form_state
->setError($element, $valid['message']);
}
}
}