You are here

public function FillPdfFormImportForm::validateForm in FillPDF 8.4

Same name and namespace in other branches
  1. 5.0.x src/Form/FillPdfFormImportForm.php \Drupal\fillpdf\Form\FillPdfFormImportForm::validateForm()

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/FillPdfFormImportForm.php, line 80

Class

FillPdfFormImportForm
Form controller for the FillPdfForm import form.

Namespace

Drupal\fillpdf\Form

Code

public function validateForm(array &$form, FormStateInterface $form_state) {
  parent::validateForm($form, $form_state);
  $code = $form_state
    ->getValue('code');
  $return = $this->serializer
    ->deserializeForm($code);

  /** @var \Drupal\fillpdf\FillPdfFormInterface $fillpdf_form */
  $fillpdf_form = $return['form'];

  /** @var \Drupal\fillpdf\FillPdfFormFieldInterface[] $fields */
  $fields = $return['fields'];
  if (!is_object($fillpdf_form) || !count($fields)) {
    $form_state
      ->setErrorByName('code', $this
      ->t('There was a problem processing your FillPDF form code. Please do a fresh export from the source and try pasting it again.'));
  }
  else {
    $form_state
      ->setValue('mappings', [
      'form' => $fillpdf_form,
      'fields' => $fields,
    ]);
  }
}