89542d34ff3f04ee17ec816c70aa84eb13f08c6f
[yaffs-website] / web / core / modules / comment / src / Plugin / Menu / LocalTask / UnapprovedComments.php
1 <?php
2
3 namespace Drupal\comment\Plugin\Menu\LocalTask;
4
5 use Drupal\comment\CommentStorageInterface;
6 use Drupal\Core\Menu\LocalTaskDefault;
7 use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
8 use Drupal\Core\StringTranslation\StringTranslationTrait;
9 use Symfony\Component\DependencyInjection\ContainerInterface;
10
11 /**
12  * Provides a local task that shows the amount of unapproved comments.
13  */
14 class UnapprovedComments extends LocalTaskDefault implements ContainerFactoryPluginInterface {
15   use StringTranslationTrait;
16
17   /**
18    * The comment storage service.
19    *
20    * @var \Drupal\comment\CommentStorageInterface
21    */
22   protected $commentStorage;
23
24   /**
25    * Construct the UnapprovedComments object.
26    *
27    * @param array $configuration
28    *   A configuration array containing information about the plugin instance.
29    * @param string $plugin_id
30    *   The plugin_id for the plugin instance.
31    * @param array $plugin_definition
32    *   The plugin implementation definition.
33    * @param \Drupal\comment\CommentStorageInterface $comment_storage
34    *   The comment storage service.
35    */
36   public function __construct(array $configuration, $plugin_id, array $plugin_definition, CommentStorageInterface $comment_storage) {
37     parent::__construct($configuration, $plugin_id, $plugin_definition);
38     $this->commentStorage = $comment_storage;
39   }
40
41   /**
42    * {@inheritdoc}
43    */
44   public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
45     return new static(
46       $configuration,
47       $plugin_id,
48       $plugin_definition,
49       $container->get('entity.manager')->getStorage('comment')
50     );
51   }
52
53   /**
54    * {@inheritdoc}
55    */
56   public function getTitle() {
57     return $this->t('Unapproved comments (@count)', ['@count' => $this->commentStorage->getUnapprovedCount()]);
58   }
59
60 }