Mercurial > hg > isophonics-drupal-site
comparison core/modules/comment/src/Plugin/Action/DeleteComment.php @ 17:129ea1e6d783
Update, including to Drupal core 8.6.10
author | Chris Cannam |
---|---|
date | Thu, 28 Feb 2019 13:21:36 +0000 |
parents | 1fec387a4317 |
children |
comparison
equal
deleted
inserted
replaced
16:c2387f117808 | 17:129ea1e6d783 |
---|---|
1 <?php | 1 <?php |
2 | 2 |
3 namespace Drupal\comment\Plugin\Action; | 3 namespace Drupal\comment\Plugin\Action; |
4 | 4 |
5 use Drupal\Core\Action\ActionBase; | 5 use Drupal\Core\Action\Plugin\Action\DeleteAction; |
6 use Drupal\Core\Plugin\ContainerFactoryPluginInterface; | 6 use Drupal\Core\Entity\EntityTypeManagerInterface; |
7 use Drupal\Core\Session\AccountInterface; | 7 use Drupal\Core\Session\AccountInterface; |
8 use Drupal\Core\TempStore\PrivateTempStoreFactory; | 8 use Drupal\Core\TempStore\PrivateTempStoreFactory; |
9 use Symfony\Component\DependencyInjection\ContainerInterface; | |
10 | 9 |
11 /** | 10 /** |
12 * Deletes a comment. | 11 * Deletes a comment. |
13 * | 12 * |
13 * @deprecated in Drupal 8.6.x, to be removed before Drupal 9.0.0. | |
14 * Use \Drupal\Core\Action\Plugin\Action\DeleteAction instead. | |
15 * | |
16 * @see \Drupal\Core\Action\Plugin\Action\DeleteAction | |
17 * @see https://www.drupal.org/node/2934349 | |
18 * | |
14 * @Action( | 19 * @Action( |
15 * id = "comment_delete_action", | 20 * id = "comment_delete_action", |
16 * label = @Translation("Delete comment"), | 21 * label = @Translation("Delete comment") |
17 * type = "comment", | |
18 * confirm_form_route_name = "comment.multiple_delete_confirm" | |
19 * ) | 22 * ) |
20 */ | 23 */ |
21 class DeleteComment extends ActionBase implements ContainerFactoryPluginInterface { | 24 class DeleteComment extends DeleteAction { |
22 | |
23 /** | |
24 * The tempstore object. | |
25 * | |
26 * @var \Drupal\Core\TempStore\PrivateTempStore | |
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 DeleteComment 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 array $plugin_definition | |
45 * The plugin implementation definition. | |
46 * @param \Drupal\Core\TempStore\PrivateTempStoreFactory $temp_store_factory | |
47 * The tempstore factory. | |
48 * @param \Drupal\Core\Session\AccountInterface $current_user | |
49 * The current user. | |
50 */ | |
51 public function __construct(array $configuration, $plugin_id, array $plugin_definition, PrivateTempStoreFactory $temp_store_factory, AccountInterface $current_user) { | |
52 $this->currentUser = $current_user; | |
53 $this->tempStore = $temp_store_factory->get('comment_multiple_delete_confirm'); | |
54 parent::__construct($configuration, $plugin_id, $plugin_definition); | |
55 } | |
56 | 25 |
57 /** | 26 /** |
58 * {@inheritdoc} | 27 * {@inheritdoc} |
59 */ | 28 */ |
60 public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { | 29 public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager, PrivateTempStoreFactory $temp_store_factory, AccountInterface $current_user) { |
61 return new static( | 30 parent::__construct($configuration, $plugin_id, $plugin_definition, $entity_type_manager, $temp_store_factory, $current_user); |
62 $configuration, | 31 @trigger_error(__NAMESPACE__ . '\DeleteComment is deprecated in Drupal 8.6.x, will be removed before Drupal 9.0.0. Use \Drupal\Core\Action\Plugin\Action\DeleteAction instead. See https://www.drupal.org/node/2934349.', E_USER_DEPRECATED); |
63 $plugin_id, | |
64 $plugin_definition, | |
65 $container->get('tempstore.private'), | |
66 $container->get('current_user') | |
67 ); | |
68 } | |
69 | |
70 /** | |
71 * {@inheritdoc} | |
72 */ | |
73 public function executeMultiple(array $entities) { | |
74 $info = []; | |
75 /** @var \Drupal\comment\CommentInterface $comment */ | |
76 foreach ($entities as $comment) { | |
77 $langcode = $comment->language()->getId(); | |
78 $info[$comment->id()][$langcode] = $langcode; | |
79 } | |
80 $this->tempStore->set($this->currentUser->id(), $info); | |
81 } | |
82 | |
83 /** | |
84 * {@inheritdoc} | |
85 */ | |
86 public function execute($entity = NULL) { | |
87 $this->executeMultiple([$entity]); | |
88 } | |
89 | |
90 /** | |
91 * {@inheritdoc} | |
92 */ | |
93 public function access($comment, AccountInterface $account = NULL, $return_as_object = FALSE) { | |
94 /** @var \Drupal\comment\CommentInterface $comment */ | |
95 return $comment->access('delete', $account, $return_as_object); | |
96 } | 32 } |
97 | 33 |
98 } | 34 } |