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;
10 use Symfony\Component\HttpFoundation\Request;
13 * Provides a local task that shows the amount of unapproved comments.
15 class UnapprovedComments extends LocalTaskDefault implements ContainerFactoryPluginInterface {
16 use StringTranslationTrait;
19 * The comment storage service.
21 * @var \Drupal\comment\CommentStorageInterface
23 protected $commentStorage;
26 * Construct the UnapprovedComments object.
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.
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;
45 public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
50 $container->get('entity.manager')->getStorage('comment')
57 public function getTitle(Request $request = NULL) {
58 return $this->t('Unapproved comments (@count)', ['@count' => $this->commentStorage->getUnapprovedCount()]);