You are here

public function IngredientWidget::validate in Recipe 8.2

Validate the ingredient field.

Parameters

array $element: The ingredient field's form element.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

File

modules/ingredient/src/Plugin/Field/FieldWidget/IngredientWidget.php, line 144

Class

IngredientWidget
Plugin implementation of the 'ingredient_autocomplete' widget.

Namespace

Drupal\ingredient\Plugin\Field\FieldWidget

Code

public function validate(array $element, FormStateInterface $form_state) {
  if (empty($element['unit_key']['#value']) && !empty($element['name']['#value'])) {
    $form_state
      ->setError($element['unit_key'], $this
      ->t('You must choose a valid unit.'));
    return;
  }
}