Newer
Older
Eric Bremner
committed
<?php
namespace Drupal\uw_cfg_common\Form;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Form\ConfirmFormBase;
Eric Bremner
committed
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
use Symfony\Component\DependencyInjection\ContainerInterface;
Eric Bremner
committed
/**
* Form class for the content access form.
*/
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
class UwContentModerationForm extends ConfirmFormBase {
/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* The nid (node id).
*
* @var int
*/
protected $nid;
/**
* The vid (version id).
*
* @var int
*/
protected $vid;
/**
* Class constructor.
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
*/
public function __construct(EntityTypeManagerInterface $entity_type_manager) {
$this->entityTypeManager = $entity_type_manager;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
// Instantiates this form class.
return new static(
$container->get('entity_type.manager')
);
}
Eric Bremner
committed
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'uw_content_moderation_form';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state, $nid = NULL, $vid = NULL) {
// Set the node and version ids.
$this->nid = $nid;
$this->vid = $vid;
Eric Bremner
committed
// Return the form from the parent (confirm form).
return parent::buildForm($form, $form_state);
Eric Bremner
committed
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
// Set the message that the permissions have been saved.
$this->messenger()->addStatus($this->t('The changes have been saved.'));
}
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/**
* Returns the question to ask the user.
*
* @return \Drupal\Core\StringTranslation\TranslatableMarkup
* The form question. The page title will be set to this value.
*/
public function getQuestion() {
// Get the node object.
$node = $this->entityTypeManager->getStorage('node')->load($this->nid);
// Return the question to see if they want to publish the node.
return t('Are you sure you want to unpublish %node_title?', ['%node_title' => $node->getTitle()]);
}
/**
* Returns the route to go to if the user cancels the action.
*
* @return \Drupal\Core\Url
* A URL object.
*/
public function getCancelUrl() {
// Set the options for the URL.
$options = ['absolute' => TRUE];
// Return the URL back to the node.
return Url::fromRoute('entity.node.canonical', ['node' => $this->nid], $options);
}