function RecipeInputFormTrait::validateRecipeInput

Validates user-inputted values to a recipe and its dependencies.

Parameters

\Drupal\Core\Recipe\Recipe $recipe: A recipe.

array $form: The form being validated, which should include the tree of elements returned by ::buildRecipeInputForm().

\Drupal\Core\Form\FormStateInterface $form_state: The current form state. The values should be organized in the tree structure that was returned by ::buildRecipeInputForm().

1 call to RecipeInputFormTrait::validateRecipeInput()
FormTestRecipeInputForm::validateForm in core/modules/system/tests/modules/form_test/src/Form/FormTestRecipeInputForm.php
Form validation handler.

File

core/lib/Drupal/Core/Recipe/RecipeInputFormTrait.php, line 107

Class

RecipeInputFormTrait
Defines helper methods for forms which collect input on behalf of recipes.

Namespace

Drupal\Core\Recipe

Code

protected function validateRecipeInput(Recipe $recipe, array &$form, FormStateInterface $form_state) : void {
  try {
    $this->setRecipeInput($recipe, $form_state);
  } catch (ValidationFailedException $e) {
    $data = $e->getValue();
    if ($data instanceof TypedDataInterface) {
      $element = NestedArray::getValue($form, explode('.', $data->getName(), 2));
      $form_state->setError($element, $e->getMessage());
    }
    else {
      // If the data isn't a typed data object, we have no idea how to handle
      // the situation, so just re-throw the exception.
      throw $e;
    }
  }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.