namespace Drupal\comment;
use Drupal\Core\Cache\CacheBackendInterface;
+use Drupal\Core\Cache\MemoryCache\MemoryCacheInterface;
use Drupal\Core\Database\Connection;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Entity\EntityTypeInterface;
* Cache backend instance to use.
* @param \Drupal\Core\Language\LanguageManagerInterface $language_manager
* The language manager.
+ * @param \Drupal\Core\Cache\MemoryCache\MemoryCacheInterface $memory_cache
+ * The memory cache.
*/
- public function __construct(EntityTypeInterface $entity_info, Connection $database, EntityManagerInterface $entity_manager, AccountInterface $current_user, CacheBackendInterface $cache, LanguageManagerInterface $language_manager) {
- parent::__construct($entity_info, $database, $entity_manager, $cache, $language_manager);
+ public function __construct(EntityTypeInterface $entity_info, Connection $database, EntityManagerInterface $entity_manager, AccountInterface $current_user, CacheBackendInterface $cache, LanguageManagerInterface $language_manager, MemoryCacheInterface $memory_cache) {
+ parent::__construct($entity_info, $database, $entity_manager, $cache, $language_manager, $memory_cache);
$this->currentUser = $current_user;
}
$container->get('entity.manager'),
$container->get('current_user'),
$container->get('cache.entity'),
- $container->get('language_manager')
+ $container->get('language_manager'),
+ $container->get('entity.memory_cache')
);
}
* {@inheritdoc}
*/
public function getMaxThread(CommentInterface $comment) {
- $query = $this->database->select('comment_field_data', 'c')
+ $query = $this->database->select($this->getDataTable(), 'c')
->condition('entity_id', $comment->getCommentedEntityId())
->condition('field_name', $comment->getFieldName())
->condition('entity_type', $comment->getCommentedEntityTypeId())
* {@inheritdoc}
*/
public function getMaxThreadPerThread(CommentInterface $comment) {
- $query = $this->database->select('comment_field_data', 'c')
+ $query = $this->database->select($this->getDataTable(), 'c')
->condition('entity_id', $comment->getCommentedEntityId())
->condition('field_name', $comment->getFieldName())
->condition('entity_type', $comment->getCommentedEntityTypeId())
public function getDisplayOrdinal(CommentInterface $comment, $comment_mode, $divisor = 1) {
// Count how many comments (c1) are before $comment (c2) in display order.
// This is the 0-based display ordinal.
- $query = $this->database->select('comment_field_data', 'c1');
- $query->innerJoin('comment_field_data', 'c2', 'c2.entity_id = c1.entity_id AND c2.entity_type = c1.entity_type AND c2.field_name = c1.field_name');
+ $data_table = $this->getDataTable();
+ $query = $this->database->select($data_table, 'c1');
+ $query->innerJoin($data_table, 'c2', 'c2.entity_id = c1.entity_id AND c2.entity_type = c1.entity_type AND c2.field_name = c1.field_name');
$query->addExpression('COUNT(*)', 'count');
$query->condition('c2.cid', $comment->id());
if (!$this->currentUser->hasPermission('administer comments')) {
public function getNewCommentPageNumber($total_comments, $new_comments, FieldableEntityInterface $entity, $field_name) {
$field = $entity->getFieldDefinition($field_name);
$comments_per_page = $field->getSetting('per_page');
+ $data_table = $this->getDataTable();
if ($total_comments <= $comments_per_page) {
// Only one page of comments.
// Threaded comments.
// 1. Find all the threads with a new comment.
- $unread_threads_query = $this->database->select('comment_field_data', 'comment')
+ $unread_threads_query = $this->database->select($data_table, 'comment')
->fields('comment', ['thread'])
->condition('entity_id', $entity->id())
->condition('entity_type', $entity->getEntityTypeId())
$first_thread = substr($first_thread, 0, -1);
// Find the number of the first comment of the first unread thread.
- $count = $this->database->query('SELECT COUNT(*) FROM {comment_field_data} WHERE entity_id = :entity_id
+ $count = $this->database->query('SELECT COUNT(*) FROM {' . $data_table . '} WHERE entity_id = :entity_id
AND entity_type = :entity_type
AND field_name = :field_name
AND status = :status
* {@inheritdoc}
*/
public function getChildCids(array $comments) {
- return $this->database->select('comment_field_data', 'c')
+ return $this->database->select($this->getDataTable(), 'c')
->fields('c', ['cid'])
->condition('pid', array_keys($comments), 'IN')
->condition('default_langcode', 1)
* to consider the trailing "/" so we use a substring only.
*/
public function loadThread(EntityInterface $entity, $field_name, $mode, $comments_per_page = 0, $pager_id = 0) {
- $query = $this->database->select('comment_field_data', 'c');
+ $data_table = $this->getDataTable();
+ $query = $this->database->select($data_table, 'c');
$query->addField('c', 'cid');
$query
->condition('c.entity_id', $entity->id())
$query->element($pager_id);
}
- $count_query = $this->database->select('comment_field_data', 'c');
+ $count_query = $this->database->select($data_table, 'c');
$count_query->addExpression('COUNT(*)');
$count_query
->condition('c.entity_id', $entity->id())
* {@inheritdoc}
*/
public function getUnapprovedCount() {
- return $this->database->select('comment_field_data', 'c')
+ return $this->database->select($this->getDataTable(), 'c')
->condition('status', CommentInterface::NOT_PUBLISHED, '=')
->condition('default_langcode', 1)
->countQuery()