annotate core/modules/comment/src/Plugin/Action/DeleteComment.php @ 0:c75dbcec494b

Initial commit from drush-created site
author Chris Cannam
date Thu, 05 Jul 2018 14:24:15 +0000
parents
children a9cd425dd02b
rev   line source
Chris@0 1 <?php
Chris@0 2
Chris@0 3 namespace Drupal\comment\Plugin\Action;
Chris@0 4
Chris@0 5 use Drupal\Core\Action\ActionBase;
Chris@0 6 use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
Chris@0 7 use Drupal\Core\Session\AccountInterface;
Chris@0 8 use Drupal\Core\TempStore\PrivateTempStoreFactory;
Chris@0 9 use Symfony\Component\DependencyInjection\ContainerInterface;
Chris@0 10
Chris@0 11 /**
Chris@0 12 * Deletes a comment.
Chris@0 13 *
Chris@0 14 * @Action(
Chris@0 15 * id = "comment_delete_action",
Chris@0 16 * label = @Translation("Delete comment"),
Chris@0 17 * type = "comment",
Chris@0 18 * confirm_form_route_name = "comment.multiple_delete_confirm"
Chris@0 19 * )
Chris@0 20 */
Chris@0 21 class DeleteComment extends ActionBase implements ContainerFactoryPluginInterface {
Chris@0 22
Chris@0 23 /**
Chris@0 24 * The tempstore object.
Chris@0 25 *
Chris@0 26 * @var \Drupal\Core\TempStore\PrivateTempStore
Chris@0 27 */
Chris@0 28 protected $tempStore;
Chris@0 29
Chris@0 30 /**
Chris@0 31 * The current user.
Chris@0 32 *
Chris@0 33 * @var \Drupal\Core\Session\AccountInterface
Chris@0 34 */
Chris@0 35 protected $currentUser;
Chris@0 36
Chris@0 37 /**
Chris@0 38 * Constructs a new DeleteComment object.
Chris@0 39 *
Chris@0 40 * @param array $configuration
Chris@0 41 * A configuration array containing information about the plugin instance.
Chris@0 42 * @param string $plugin_id
Chris@0 43 * The plugin ID for the plugin instance.
Chris@0 44 * @param array $plugin_definition
Chris@0 45 * The plugin implementation definition.
Chris@0 46 * @param \Drupal\Core\TempStore\PrivateTempStoreFactory $temp_store_factory
Chris@0 47 * The tempstore factory.
Chris@0 48 * @param \Drupal\Core\Session\AccountInterface $current_user
Chris@0 49 * The current user.
Chris@0 50 */
Chris@0 51 public function __construct(array $configuration, $plugin_id, array $plugin_definition, PrivateTempStoreFactory $temp_store_factory, AccountInterface $current_user) {
Chris@0 52 $this->currentUser = $current_user;
Chris@0 53 $this->tempStore = $temp_store_factory->get('comment_multiple_delete_confirm');
Chris@0 54 parent::__construct($configuration, $plugin_id, $plugin_definition);
Chris@0 55 }
Chris@0 56
Chris@0 57 /**
Chris@0 58 * {@inheritdoc}
Chris@0 59 */
Chris@0 60 public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
Chris@0 61 return new static(
Chris@0 62 $configuration,
Chris@0 63 $plugin_id,
Chris@0 64 $plugin_definition,
Chris@0 65 $container->get('tempstore.private'),
Chris@0 66 $container->get('current_user')
Chris@0 67 );
Chris@0 68 }
Chris@0 69
Chris@0 70 /**
Chris@0 71 * {@inheritdoc}
Chris@0 72 */
Chris@0 73 public function executeMultiple(array $entities) {
Chris@0 74 $info = [];
Chris@0 75 /** @var \Drupal\comment\CommentInterface $comment */
Chris@0 76 foreach ($entities as $comment) {
Chris@0 77 $langcode = $comment->language()->getId();
Chris@0 78 $info[$comment->id()][$langcode] = $langcode;
Chris@0 79 }
Chris@0 80 $this->tempStore->set($this->currentUser->id(), $info);
Chris@0 81 }
Chris@0 82
Chris@0 83 /**
Chris@0 84 * {@inheritdoc}
Chris@0 85 */
Chris@0 86 public function execute($entity = NULL) {
Chris@0 87 $this->executeMultiple([$entity]);
Chris@0 88 }
Chris@0 89
Chris@0 90 /**
Chris@0 91 * {@inheritdoc}
Chris@0 92 */
Chris@0 93 public function access($comment, AccountInterface $account = NULL, $return_as_object = FALSE) {
Chris@0 94 /** @var \Drupal\comment\CommentInterface $comment */
Chris@0 95 return $comment->access('delete', $account, $return_as_object);
Chris@0 96 }
Chris@0 97
Chris@0 98 }