3 namespace Drupal\comment\Plugin\Menu\LocalTask;
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;
12 * Provides a local task that shows the amount of unapproved comments.
14 class UnapprovedComments extends LocalTaskDefault implements ContainerFactoryPluginInterface {
15 use StringTranslationTrait;
18 * The comment storage service.
20 * @var \Drupal\comment\CommentStorageInterface
22 protected $commentStorage;
25 * Construct the UnapprovedComments object.
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.
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;
44 public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
49 $container->get('entity.manager')->getStorage('comment')
56 public function getTitle() {
57 return $this->t('Unapproved comments (@count)', ['@count' => $this->commentStorage->getUnapprovedCount()]);