You are here

public function FormsStepsStepFormBase::validateForm in Forms Steps 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/FormsStepsStepFormBase.php, line 531

Class

FormsStepsStepFormBase
Class FormsStepsStepFormBase.

Namespace

Drupal\forms_steps\Form

Code

public function validateForm(array &$form, FormStateInterface $form_state) {
  if ($form_state
    ->isSubmitted()) {
    parent::validateForm($form, $form_state);
    $values = $form_state
      ->getValues();
    $entityFormDisplay = \Drupal::service('entity_display.repository')
      ->getFormDisplay($values['target_entity_type'], $values['target_entity_bundle'], preg_replace("/^{$values['target_entity_type']}\\./", '', $values['target_form_mode']));
    if ($entityFormDisplay
      ->isNew()) {
      $form_state
        ->setErrorByName('target_form_mode', $this
        ->t('This form mode is not yet defined for the selected bundle.'));
    }
  }
}