3 namespace Drupal\comment\Plugin\Action;
5 use Drupal\Core\Action\ActionBase;
6 use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
7 use Drupal\Core\Session\AccountInterface;
8 use Drupal\Core\TempStore\PrivateTempStoreFactory;
9 use Symfony\Component\DependencyInjection\ContainerInterface;
15 * id = "comment_delete_action",
16 * label = @Translation("Delete comment"),
18 * confirm_form_route_name = "comment.multiple_delete_confirm"
21 class DeleteComment extends ActionBase implements ContainerFactoryPluginInterface {
24 * The tempstore object.
26 * @var \Drupal\Core\TempStore\PrivateTempStore
33 * @var \Drupal\Core\Session\AccountInterface
35 protected $currentUser;
38 * Constructs a new DeleteComment object.
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
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);
60 public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
65 $container->get('tempstore.private'),
66 $container->get('current_user')
73 public function executeMultiple(array $entities) {
75 /** @var \Drupal\comment\CommentInterface $comment */
76 foreach ($entities as $comment) {
77 $langcode = $comment->language()->getId();
78 $info[$comment->id()][$langcode] = $langcode;
80 $this->tempStore->set($this->currentUser->id(), $info);
86 public function execute($entity = NULL) {
87 $this->executeMultiple([$entity]);
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);