You are here

public function EntityFormWizardBase::finish in Chaos Tool Suite (ctools) 8.3

Form submit handler for finalizing the wizard values.

If you need to generate an entity or save config or raw table data subsequent to your form wizard, this is the responsible method.

Parameters

array $form: Drupal form array.

\Drupal\Core\Form\FormStateInterface $form_state: The final form state of the wizard.

Overrides FormWizardBase::finish

File

src/Wizard/EntityFormWizardBase.php, line 95

Class

EntityFormWizardBase
The base class for all entity form wizards.

Namespace

Drupal\ctools\Wizard

Code

public function finish(array &$form, FormStateInterface $form_state) {
  $cached_values = $form_state
    ->getTemporaryValue('wizard');

  /** @var \Drupal\Core\Entity\EntityInterface $entity */
  $entity = $cached_values[$this
    ->getEntityType()];
  $entity
    ->set('id', $cached_values['id']);
  $entity
    ->set('label', $cached_values['label']);
  $status = $entity
    ->save();
  $arguments = [
    '@entity-type' => $entity
      ->getEntityType()
      ->getSingularLabel(),
    '%label' => $entity
      ->label(),
  ];
  if ($status === SAVED_UPDATED) {
    $this
      ->messenger()
      ->addMessage($this
      ->t('The @entity-type %label has been updated.', $arguments));
    $this
      ->logger($entity
      ->getEntityType()
      ->getProvider())
      ->notice('Updated @entity-type %label.', $arguments);
  }
  elseif ($status === SAVED_NEW) {
    $this
      ->messenger()
      ->addMessage($this
      ->t('The @entity-type %label has been added.', $arguments));
    $this
      ->logger($entity
      ->getEntityType()
      ->getProvider())
      ->notice('Added @entity-type %label.', $arguments);
  }
  $form_state
    ->setRedirectUrl($entity
    ->toUrl('collection'));
  parent::finish($form, $form_state);
}