Commit 81604eed authored by webchick's avatar webchick

Issue #2111357 by marcingy, andypost: Get rid of comment_count_unpublished()...

Issue #2111357 by marcingy, andypost: Get rid of comment_count_unpublished() in favor of CommentStorage method.
parent 04bf43bb
......@@ -155,18 +155,6 @@ function comment_theme() {
);
}
/**
* Returns a menu title which includes the number of unapproved comments.
*
* @todo Move to the comment manager and replace by a entity query?
*/
function comment_count_unpublished() {
$count = db_query('SELECT COUNT(cid) FROM {comment} WHERE status = :status', array(
':status' => CommentInterface::NOT_PUBLISHED,
))->fetchField();
return t('Unapproved comments (@count)', array('@count' => $count));
}
/**
* Implements hook_ENTITY_TYPE_create() for 'field_instance_config'.
*/
......
......@@ -172,4 +172,15 @@ public function getSchema() {
return $schema;
}
/**
* {@inheritdoc}
*/
public function getUnapprovedCount() {
return $this->database->select('comment', 'c')
->condition('status', CommentInterface::NOT_PUBLISHED, '=')
->countQuery()
->execute()
->fetchField();
}
}
......@@ -66,4 +66,12 @@ public function getChildCids(array $comments);
*/
public function updateEntityStatistics(CommentInterface $comment);
/**
* Returns the number of unapproved comments.
*
* @return int
* The number of unapproved comments.
*/
public function getUnapprovedCount();
}
......@@ -7,18 +7,57 @@
namespace Drupal\comment\Plugin\Menu\LocalTask;
use Drupal\comment\CommentStorageInterface;
use Drupal\Core\Menu\LocalTaskDefault;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Provides a local task that shows the amount of unapproved comments.
*/
class UnapprovedComments extends LocalTaskDefault {
class UnapprovedComments extends LocalTaskDefault implements ContainerFactoryPluginInterface {
/**
* The comment storage service.
*
* @var \Drupal\comment\CommentStorageInterface
*/
protected $commentStorage;
/**
* Construct the UnapprovedComments object.
*
* @param array $configuration
* A configuration array containing information about the plugin instance.
* @param string $plugin_id
* The plugin_id for the plugin instance.
* @param array $plugin_definition
* The plugin implementation definition.
* @param \Drupal\comment\CommentStorageInterface $comment_storage
* The comment storage service.
*/
public function __construct(array $configuration, $plugin_id, array $plugin_definition, CommentStorageInterface $comment_storage) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->commentStorage = $comment_storage;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static(
$configuration,
$plugin_id,
$plugin_definition,
$container->get('entity.manager')->getStorage('comment')
);
}
/**
* {@inheritdoc}
*/
public function getTitle() {
return comment_count_unpublished();
return t('Unapproved comments (@count)', array('@count' => $this->commentStorage->getUnapprovedCount()));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment