Further Drupal 8.6.4 changes. Some core files were not committed before a commit...
[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 use Symfony\Component\HttpFoundation\Request;
11
12 /**
13  * Provides a local task that shows the amount of unapproved comments.
14  */
15 class UnapprovedComments extends LocalTaskDefault implements ContainerFactoryPluginInterface {
16   use StringTranslationTrait;
17
18   /**
19    * The comment storage service.
20    *
21    * @var \Drupal\comment\CommentStorageInterface
22    */
23   protected $commentStorage;
24
25   /**
26    * Construct the UnapprovedComments object.
27    *
28    * @param array $configuration
29    *   A configuration array containing information about the plugin instance.
30    * @param string $plugin_id
31    *   The plugin_id for the plugin instance.
32    * @param array $plugin_definition
33    *   The plugin implementation definition.
34    * @param \Drupal\comment\CommentStorageInterface $comment_storage
35    *   The comment storage service.
36    */
37   public function __construct(array $configuration, $plugin_id, array $plugin_definition, CommentStorageInterface $comment_storage) {
38     parent::__construct($configuration, $plugin_id, $plugin_definition);
39     $this->commentStorage = $comment_storage;
40   }
41
42   /**
43    * {@inheritdoc}
44    */
45   public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
46     return new static(
47       $configuration,
48       $plugin_id,
49       $plugin_definition,
50       $container->get('entity.manager')->getStorage('comment')
51     );
52   }
53
54   /**
55    * {@inheritdoc}
56    */
57   public function getTitle(Request $request = NULL) {
58     return $this->t('Unapproved comments (@count)', ['@count' => $this->commentStorage->getUnapprovedCount()]);
59   }
60
61 }