You are here

public function EmbedButtonForm::validateForm in Embed 8

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/EmbedButtonForm.php, line 171

Class

EmbedButtonForm
Form controller for embed button forms.

Namespace

Drupal\embed\Form

Code

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

  /** @var \Drupal\embed\EmbedButtonInterface $button */
  $button = $this->entity;

  // Run embed type plugin validation.
  if ($plugin = $button
    ->getTypePlugin()) {
    $plugin_form_state = clone $form_state;
    $plugin_form_state
      ->setValues($button
      ->getTypeSettings());
    $plugin
      ->validateConfigurationForm($form['type_settings'], $plugin_form_state);
    if ($errors = $plugin_form_state
      ->getErrors()) {
      foreach ($errors as $name => $error) {
        $form_state
          ->setErrorByName($name, $error);
      }
    }
    $form_state
      ->setValue('type_settings', $plugin_form_state
      ->getValues());
  }
}