CandidateNodesRevisionsDeleteForm.php in Node Revision Delete 8
File
src/Form/CandidateNodesRevisionsDeleteForm.php
View source
<?php
namespace Drupal\node_revision_delete\Form;
use Drupal\Core\Form\ConfirmFormBase;
use Drupal\Core\Form\FormStateInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Url;
use Drupal\node_revision_delete\NodeRevisionDeleteInterface;
use Drupal\node\NodeInterface;
class CandidateNodesRevisionsDeleteForm extends ConfirmFormBase {
protected $node;
protected $nodeRevisionDelete;
public function __construct(NodeRevisionDeleteInterface $node_revision_delete) {
$this->nodeRevisionDelete = $node_revision_delete;
}
public static function create(ContainerInterface $container) {
return new static($container
->get('node_revision_delete'));
}
public function getFormId() {
return 'node_revision_delete_candidates_nodes_revisions_delete';
}
public function buildForm(array $form, FormStateInterface $form_state, $node_type = NULL, NodeInterface $node = NULL) {
$this->node = $node;
return parent::buildForm($form, $form_state);
}
public function getQuestion() {
return $this
->t('Are you sure you want to delete the candidates revisions for the node "%node_title" ?', [
'%node_title' => $this->node
->getTitle(),
]);
}
public function getConfirmText() {
return $this
->t('Delete');
}
public function getDescription() {
$description = '<p>' . $this
->t('This action will delete the candidate revisions for the "@node_title" content type.', [
'@node_title' => $this->node
->getTitle(),
]) . '</p>';
$description .= '<p>' . parent::getDescription() . '</p>';
return $description;
}
public function getCancelText() {
return $this
->t('Cancel');
}
public function getCancelUrl() {
return new Url('node_revision_delete.candidate_nodes', [
'node_type' => $this->node
->getType(),
]);
}
public function submitForm(array &$form, FormStateInterface $form_state) {
$candidate_revisions = $this->nodeRevisionDelete
->getCandidatesRevisionsByNids([
$this->node
->id(),
]);
batch_set($this->nodeRevisionDelete
->getRevisionDeletionBatch($candidate_revisions, FALSE));
$form_state
->setRedirectUrl($this
->getCancelUrl());
}
}