You are here

public function FillPdfOverviewForm::submitForm in FillPDF 5.0.x

Same name and namespace in other branches
  1. 8.4 src/Form/FillPdfOverviewForm.php \Drupal\fillpdf\Form\FillPdfOverviewForm::submitForm()

Form submission 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 FormInterface::submitForm

File

src/Form/FillPdfOverviewForm.php, line 156

Class

FillPdfOverviewForm
FillPDF overview form.

Namespace

Drupal\fillpdf\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  if ($form_state
    ->getValue('upload_pdf')) {

    /** @var \Drupal\file\FileInterface $file */
    $file = File::load($form_state
      ->getValue('upload_pdf')['0']);
    $added = $this->inputHelper
      ->attachPdfToForm($file);

    /** @var \Drupal\fillpdf\Entity\FillPdfForm $fillpdf_form */
    $fillpdf_form = $added['form'];
    $fid = $fillpdf_form
      ->id();
    $this
      ->logger('fillpdf')
      ->notice('Added FillPDF form %id.', [
      '%id' => $fid,
    ]);
    $this
      ->messenger()
      ->addStatus($this
      ->t('New FillPDF form has been created.'));

    /** @var \Drupal\fillpdf\FillPdfFormFieldInterface[] $form_fields */
    $form_fields = $added['fields'];
    if (count($form_fields) === 0) {
      $this
        ->messenger()
        ->addWarning($this
        ->t('No fields detected in PDF. Are you sure it contains editable fields?'));
    }
    else {
      $this
        ->messenger()
        ->addStatus($this
        ->t("You may now create mappings between the fields of the PDF form and an entity type."));
    }
    $form_state
      ->setRedirect('entity.fillpdf_form.edit_form', [
      'fillpdf_form' => $fid,
    ]);
  }
}