You are here

public function EntityLegalDocumentAcceptanceForm::submitForm in Entity Legal 4.0.x

Same name and namespace in other branches
  1. 8.2 src/Form/EntityLegalDocumentAcceptanceForm.php \Drupal\entity_legal\Form\EntityLegalDocumentAcceptanceForm::submitForm()
  2. 3.0.x src/Form/EntityLegalDocumentAcceptanceForm.php \Drupal\entity_legal\Form\EntityLegalDocumentAcceptanceForm::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/EntityLegalDocumentAcceptanceForm.php, line 90

Class

EntityLegalDocumentAcceptanceForm
Provides a confirmation form for deleting a custom block entity.

Namespace

Drupal\entity_legal\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $published_version = $this->document
    ->getPublishedVersion();
  \Drupal::entityTypeManager()
    ->getStorage(ENTITY_LEGAL_DOCUMENT_ACCEPTANCE_ENTITY_NAME)
    ->create([
    'document_version_name' => $published_version
      ->id(),
  ])
    ->save();

  // Restore potential postponed messages and show them on the correct page.
  // @see \Drupal\entity_legal\Plugin\EntityLegal\Redirect::execute()
  if ($grouped_messages = $this->tempStore
    ->get('postponed_messages')) {
    foreach ($grouped_messages as $type => $messages) {
      foreach ($messages as $message) {
        $this
          ->messenger()
          ->addMessage($message, $type);
      }
    }
    $this->tempStore
      ->delete('postponed_messages');
  }
}