function NodeRevisionDeleteForm::submitForm

Same name in other branches
  1. 9 core/modules/node/src/Form/NodeRevisionDeleteForm.php \Drupal\node\Form\NodeRevisionDeleteForm::submitForm()
  2. 8.9.x core/modules/node/src/Form/NodeRevisionDeleteForm.php \Drupal\node\Form\NodeRevisionDeleteForm::submitForm()
  3. 11.x core/modules/node/src/Form/NodeRevisionDeleteForm.php \Drupal\node\Form\NodeRevisionDeleteForm::submitForm()

Overrides FormInterface::submitForm

File

core/modules/node/src/Form/NodeRevisionDeleteForm.php, line 144

Class

NodeRevisionDeleteForm
Provides a form for deleting a node revision.

Namespace

Drupal\node\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
    
    /** @var \Drupal\Core\Entity\RevisionableStorageInterface $storage */
    $storage = $this->nodeStorage;
    $storage->deleteRevision($this->revision
        ->getRevisionId());
    $this->logger('content')
        ->info('@type: deleted %title revision %revision.', [
        '@type' => $this->revision
            ->bundle(),
        '%title' => $this->revision
            ->label(),
        '%revision' => $this->revision
            ->getRevisionId(),
    ]);
    $node_type = $this->nodeTypeStorage
        ->load($this->revision
        ->bundle())
        ->label();
    $this->messenger()
        ->addStatus($this->t('Revision from %revision-date of @type %title has been deleted.', [
        '%revision-date' => $this->dateFormatter
            ->format($this->revision
            ->getRevisionCreationTime()),
        '@type' => $node_type,
        '%title' => $this->revision
            ->label(),
    ]));
    // Set redirect to the revisions history page.
    $route_name = 'entity.node.version_history';
    $parameters = [
        'node' => $this->revision
            ->id(),
    ];
    // If no revisions found, or the user does not have access to the revisions
    // page, then redirect to the canonical node page instead.
    if (!$this->accessManager
        ->checkNamedRoute($route_name, $parameters) || count($this->nodeStorage
        ->revisionIds($this->revision)) === 1) {
        $route_name = 'entity.node.canonical';
    }
    $form_state->setRedirect($route_name, $parameters);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.