You are here

public function ParserConfigurationForm::validateForm in Markdown 8.2

Form validation handler.

Parameters

array $form: An associative array containing the structure of the form.

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

Overrides FormBase::validateForm

File

src/Form/ParserConfigurationForm.php, line 743

Class

ParserConfigurationForm
Form for modifying parser configuration.

Namespace

Drupal\markdown\Form

Code

public function validateForm(array &$form, FormStateInterface $form_state) {
  parent::validateForm($form, $form_state);

  // Extract the values from the form.
  $values = $form_state
    ->cleanValues()
    ->getValues();

  // Determine the parser identifier.
  $parserId = isset($values['id']) ? (string) $values['id'] : $this
    ->getParser()
    ->getOriginalPluginId();

  // Normalize parser values into config data.
  $config = $this
    ->getConfigFromValues("markdown.parser.{$parserId}", $values);
  $typed_config = $this->typedConfigManager
    ->createFromNameAndData("markdown.parser.{$parserId}", $config
    ->get());
  $violations = $typed_config
    ->validate();
  foreach ($violations as $violation) {
    $form_state
      ->setErrorByName(static::mapViolationPropertyPathsToFormNames($violation
      ->getPropertyPath()), $violation
      ->getMessage());
  }
}