Yaffs site version 1.1
[yaffs-website] / vendor / drupal / console / templates / module / src / Entity / Form / entity-content-revision-delete.php.twig
1 {% extends "base/class.php.twig" %}
2
3 {% block file_path %}
4 \Drupal\{{module}}\Form\{{ entity_class }}RevisionDeleteForm.
5 {% endblock %}
6
7 {% block namespace_class %}
8 namespace Drupal\{{module}}\Form;
9 {% endblock %}
10
11 {% block use_class %}
12 use Drupal\Core\Database\Connection;
13 use Drupal\Core\Entity\EntityStorageInterface;
14 use Drupal\Core\Form\ConfirmFormBase;
15 use Drupal\Core\Form\FormStateInterface;
16 use Drupal\Core\Url;
17 use Symfony\Component\DependencyInjection\ContainerInterface;
18 {% endblock %}
19
20 {% block class_declaration %}
21 /**
22  * Provides a form for deleting a {{ label }} revision.
23  *
24  * @ingroup {{module}}
25  */
26 class {{ entity_class }}RevisionDeleteForm extends ConfirmFormBase {% endblock %}
27 {% block class_methods %}
28
29   /**
30    * The {{ label }} revision.
31    *
32    * @var \Drupal\{{module}}\Entity\{{ entity_class }}Interface
33    */
34   protected $revision;
35
36   /**
37    * The {{ label }} storage.
38    *
39    * @var \Drupal\Core\Entity\EntityStorageInterface
40    */
41   protected ${{ entity_class }}Storage;
42
43   /**
44    * The database connection.
45    *
46    * @var \Drupal\Core\Database\Connection
47    */
48   protected $connection;
49
50   /**
51    * Constructs a new {{ entity_class }}RevisionDeleteForm.
52    *
53    * @param \Drupal\Core\Entity\EntityStorageInterface $entity_storage
54    *   The entity storage.
55    * @param \Drupal\Core\Database\Connection $connection
56    *   The database connection.
57    */
58   public function __construct(EntityStorageInterface $entity_storage, Connection $connection) {
59     $this->{{ entity_class }}Storage = $entity_storage;
60     $this->connection = $connection;
61   }
62
63   /**
64    * {@inheritdoc}
65    */
66   public static function create(ContainerInterface $container) {
67     $entity_manager = $container->get('entity.manager');
68     return new static(
69       $entity_manager->getStorage('{{ entity_name }}'),
70       $container->get('database')
71     );
72   }
73
74   /**
75    * {@inheritdoc}
76    */
77   public function getFormId() {
78     return '{{ entity_name }}_revision_delete_confirm';
79   }
80
81   /**
82    * {@inheritdoc}
83    */
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())]);
86   }
87
88   /**
89    * {@inheritdoc}
90    */
91   public function getCancelUrl() {
92     return new Url('entity.{{ entity_name }}.version_history', ['{{ entity_name }}' => $this->revision->id()]);
93   }
94
95   /**
96    * {@inheritdoc}
97    */
98   public function getConfirmText() {
99     return t('Delete');
100   }
101
102   /**
103    * {@inheritdoc}
104    */
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);
108
109     return $form;
110   }
111
112   /**
113    * {@inheritdoc}
114    */
115   public function submitForm(array &$form, FormStateInterface $form_state) {
116     $this->{{ entity_class }}Storage->deleteRevision($this->revision->getRevisionId());
117
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()]
123     );
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()]
128       );
129     }
130   }
131 {% endblock %}