function EntityFormWizardBase::finish

Same name in other branches
  1. 8.x-3.x src/Wizard/EntityFormWizardBase.php \Drupal\ctools\Wizard\EntityFormWizardBase::finish()

Overrides FormWizardBase::finish

File

src/Wizard/EntityFormWizardBase.php, line 97

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);
}