Mercurial > hg > isophonics-drupal-site
comparison core/modules/node/src/Plugin/Action/DeleteNode.php @ 0:4c8ae668cc8c
Initial import (non-working)
author | Chris Cannam |
---|---|
date | Wed, 29 Nov 2017 16:09:58 +0000 |
parents | |
children | 7a779792577d |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4c8ae668cc8c |
---|---|
1 <?php | |
2 | |
3 namespace Drupal\node\Plugin\Action; | |
4 | |
5 use Drupal\Core\Action\ActionBase; | |
6 use Drupal\Core\Plugin\ContainerFactoryPluginInterface; | |
7 use Drupal\Core\Session\AccountInterface; | |
8 use Drupal\user\PrivateTempStoreFactory; | |
9 use Symfony\Component\DependencyInjection\ContainerInterface; | |
10 | |
11 /** | |
12 * Redirects to a node deletion form. | |
13 * | |
14 * @Action( | |
15 * id = "node_delete_action", | |
16 * label = @Translation("Delete content"), | |
17 * type = "node", | |
18 * confirm_form_route_name = "node.multiple_delete_confirm" | |
19 * ) | |
20 */ | |
21 class DeleteNode extends ActionBase implements ContainerFactoryPluginInterface { | |
22 | |
23 /** | |
24 * The tempstore object. | |
25 * | |
26 * @var \Drupal\user\SharedTempStore | |
27 */ | |
28 protected $tempStore; | |
29 | |
30 /** | |
31 * The current user. | |
32 * | |
33 * @var \Drupal\Core\Session\AccountInterface | |
34 */ | |
35 protected $currentUser; | |
36 | |
37 /** | |
38 * Constructs a new DeleteNode object. | |
39 * | |
40 * @param array $configuration | |
41 * A configuration array containing information about the plugin instance. | |
42 * @param string $plugin_id | |
43 * The plugin ID for the plugin instance. | |
44 * @param mixed $plugin_definition | |
45 * The plugin implementation definition. | |
46 * @param \Drupal\user\PrivateTempStoreFactory $temp_store_factory | |
47 * The tempstore factory. | |
48 * @param AccountInterface $current_user | |
49 * Current user. | |
50 */ | |
51 public function __construct(array $configuration, $plugin_id, $plugin_definition, PrivateTempStoreFactory $temp_store_factory, AccountInterface $current_user) { | |
52 $this->currentUser = $current_user; | |
53 $this->tempStore = $temp_store_factory->get('node_multiple_delete_confirm'); | |
54 | |
55 parent::__construct($configuration, $plugin_id, $plugin_definition); | |
56 } | |
57 | |
58 /** | |
59 * {@inheritdoc} | |
60 */ | |
61 public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { | |
62 return new static( | |
63 $configuration, | |
64 $plugin_id, | |
65 $plugin_definition, | |
66 $container->get('user.private_tempstore'), | |
67 $container->get('current_user') | |
68 ); | |
69 } | |
70 | |
71 /** | |
72 * {@inheritdoc} | |
73 */ | |
74 public function executeMultiple(array $entities) { | |
75 $info = []; | |
76 /** @var \Drupal\node\NodeInterface $node */ | |
77 foreach ($entities as $node) { | |
78 $langcode = $node->language()->getId(); | |
79 $info[$node->id()][$langcode] = $langcode; | |
80 } | |
81 $this->tempStore->set($this->currentUser->id(), $info); | |
82 } | |
83 | |
84 /** | |
85 * {@inheritdoc} | |
86 */ | |
87 public function execute($object = NULL) { | |
88 $this->executeMultiple([$object]); | |
89 } | |
90 | |
91 /** | |
92 * {@inheritdoc} | |
93 */ | |
94 public function access($object, AccountInterface $account = NULL, $return_as_object = FALSE) { | |
95 /** @var \Drupal\node\NodeInterface $object */ | |
96 return $object->access('delete', $account, $return_as_object); | |
97 } | |
98 | |
99 } |