You are here

public function ContactAutocompleteWidget::validate in RedHen CRM 8

Validate the autocomplete field.

File

modules/redhen_contact/src/Plugin/Field/FieldWidget/ContactAutocompleteWidget.php, line 115

Class

ContactAutocompleteWidget
Plugin implementation of the 'redhen_contact_autocomplete' widget.

Namespace

Drupal\redhen_contact\Plugin\Field\FieldWidget

Code

public function validate($element, FormStateInterface $form_state) {
  $element_value = $element['#value'];
  $target_id = EntityAutocomplete::extractEntityIdFromAutocompleteInput($element_value);
  if ($element_value && !$target_id) {
    $form_state
      ->setError($element, $this
      ->t('Invalid value.'));
  }
  $form_state
    ->setValueForElement($element, $target_id);
}