1 {% extends "base/class.php.twig" %}
4 \Drupal\{{module}}\Form\{{ entity_class }}RevisionDeleteForm.
7 {% block namespace_class %}
8 namespace Drupal\{{module}}\Form;
12 use Drupal\Core\Database\Connection;
13 use Drupal\Core\Entity\EntityStorageInterface;
14 use Drupal\Core\Form\ConfirmFormBase;
15 use Drupal\Core\Form\FormStateInterface;
17 use Symfony\Component\DependencyInjection\ContainerInterface;
20 {% block class_declaration %}
22 * Provides a form for deleting a {{ label }} revision.
26 class {{ entity_class }}RevisionDeleteForm extends ConfirmFormBase {% endblock %}
27 {% block class_methods %}
30 * The {{ label }} revision.
32 * @var \Drupal\{{module}}\Entity\{{ entity_class }}Interface
37 * The {{ label }} storage.
39 * @var \Drupal\Core\Entity\EntityStorageInterface
41 protected ${{ entity_class }}Storage;
44 * The database connection.
46 * @var \Drupal\Core\Database\Connection
48 protected $connection;
51 * Constructs a new {{ entity_class }}RevisionDeleteForm.
53 * @param \Drupal\Core\Entity\EntityStorageInterface $entity_storage
55 * @param \Drupal\Core\Database\Connection $connection
56 * The database connection.
58 public function __construct(EntityStorageInterface $entity_storage, Connection $connection) {
59 $this->{{ entity_class }}Storage = $entity_storage;
60 $this->connection = $connection;
66 public static function create(ContainerInterface $container) {
67 $entity_manager = $container->get('entity.manager');
69 $entity_manager->getStorage('{{ entity_name }}'),
70 $container->get('database')
77 public function getFormId() {
78 return '{{ entity_name }}_revision_delete_confirm';
84 public function getQuestion() {
85 return t('Are you sure you want to delete the revision from %revision-date?', ['%revision-date' => format_date($this->revision->getRevisionCreationTime())]);
91 public function getCancelUrl() {
92 return new Url('entity.{{ entity_name }}.version_history', ['{{ entity_name }}' => $this->revision->id()]);
98 public function getConfirmText() {
105 public function buildForm(array $form, FormStateInterface $form_state, ${{ entity_name }}_revision = NULL) {
106 $this->revision = $this->{{ entity_class }}Storage->loadRevision(${{ entity_name }}_revision);
107 $form = parent::buildForm($form, $form_state);
115 public function submitForm(array &$form, FormStateInterface $form_state) {
116 $this->{{ entity_class }}Storage->deleteRevision($this->revision->getRevisionId());
118 $this->logger('content')->notice('{{ label }}: deleted %title revision %revision.', ['%title' => $this->revision->label(), '%revision' => $this->revision->getRevisionId()]);
119 drupal_set_message(t('Revision from %revision-date of {{ label }} %title has been deleted.', ['%revision-date' => format_date($this->revision->getRevisionCreationTime()), '%title' => $this->revision->label()]));
120 $form_state->setRedirect(
121 'entity.{{ entity_name }}.canonical',
122 ['{{ entity_name }}' => $this->revision->id()]
124 if ($this->connection->query('SELECT COUNT(DISTINCT vid) FROM {{ '{'~entity_name~'_field_revision}' }} WHERE id = :id', [':id' => $this->revision->id()])->fetchField() > 1) {
125 $form_state->setRedirect(
126 'entity.{{ entity_name }}.version_history',
127 ['{{ entity_name }}' => $this->revision->id()]