You are here

public function CommentPostActivityFormatter::loadThread in Open Social 8.6

Same name and namespace in other branches
  1. 8.9 modules/social_features/social_post/src/Plugin/Field/FieldFormatter/CommentPostActivityFormatter.php \Drupal\social_post\Plugin\Field\FieldFormatter\CommentPostActivityFormatter::loadThread()
  2. 8.7 modules/social_features/social_post/src/Plugin/Field/FieldFormatter/CommentPostActivityFormatter.php \Drupal\social_post\Plugin\Field\FieldFormatter\CommentPostActivityFormatter::loadThread()
  3. 8.8 modules/social_features/social_post/src/Plugin/Field/FieldFormatter/CommentPostActivityFormatter.php \Drupal\social_post\Plugin\Field\FieldFormatter\CommentPostActivityFormatter::loadThread()
  4. 10.3.x modules/social_features/social_post/src/Plugin/Field/FieldFormatter/CommentPostActivityFormatter.php \Drupal\social_post\Plugin\Field\FieldFormatter\CommentPostActivityFormatter::loadThread()
  5. 10.0.x modules/social_features/social_post/src/Plugin/Field/FieldFormatter/CommentPostActivityFormatter.php \Drupal\social_post\Plugin\Field\FieldFormatter\CommentPostActivityFormatter::loadThread()
  6. 10.1.x modules/social_features/social_post/src/Plugin/Field/FieldFormatter/CommentPostActivityFormatter.php \Drupal\social_post\Plugin\Field\FieldFormatter\CommentPostActivityFormatter::loadThread()
  7. 10.2.x modules/social_features/social_post/src/Plugin/Field/FieldFormatter/CommentPostActivityFormatter.php \Drupal\social_post\Plugin\Field\FieldFormatter\CommentPostActivityFormatter::loadThread()

Overrides CommentPostFormatter::loadThread

See also

Drupal\comment\CommentStorage::loadThead()

File

modules/social_features/social_post/src/Plugin/Field/FieldFormatter/CommentPostActivityFormatter.php, line 30

Class

CommentPostActivityFormatter
Provides a post comment activity formatter.

Namespace

Drupal\social_post\Plugin\Field\FieldFormatter

Code

public function loadThread(EntityInterface $entity, $field_name, $mode, $comments_per_page = 0, $pager_id = 0) {

  // @TODO: Refactor this to use CommentDefaultFormatter->loadThread with dependency injection instead.
  $query = db_select('comment_field_data', 'c');
  $query
    ->addField('c', 'cid');
  $query
    ->condition('c.entity_id', $entity
    ->id())
    ->condition('c.entity_type', $entity
    ->getEntityTypeId())
    ->condition('c.field_name', $field_name)
    ->condition('c.default_langcode', 1)
    ->addTag('entity_access')
    ->addTag('comment_filter')
    ->addMetaData('base_table', 'comment')
    ->addMetaData('entity', $entity)
    ->addMetaData('field_name', $field_name);
  if (!$this->currentUser
    ->hasPermission('administer comments')) {
    $query
      ->condition('c.status', CommentInterface::PUBLISHED);
  }
  $query
    ->orderBy('c.cid', 'DESC');

  // Limit The number of results.
  if ($comments_per_page) {
    $query
      ->range(0, $comments_per_page);
  }
  $cids = $query
    ->execute()
    ->fetchCol();
  $comments = [];
  if ($cids) {
    krsort($cids);
    $comments = entity_load_multiple('comment', $cids);
  }
  return $comments;
}