public function CommentPostFormatter::loadThread in Open Social 8.8
Same name and namespace in other branches
- 8.9 modules/social_features/social_post/src/Plugin/Field/FieldFormatter/CommentPostFormatter.php \Drupal\social_post\Plugin\Field\FieldFormatter\CommentPostFormatter::loadThread()
- 8 modules/social_features/social_post/src/Plugin/Field/FieldFormatter/CommentPostFormatter.php \Drupal\social_post\Plugin\Field\FieldFormatter\CommentPostFormatter::loadThread()
- 8.2 modules/social_features/social_post/src/Plugin/Field/FieldFormatter/CommentPostFormatter.php \Drupal\social_post\Plugin\Field\FieldFormatter\CommentPostFormatter::loadThread()
- 8.3 modules/social_features/social_post/src/Plugin/Field/FieldFormatter/CommentPostFormatter.php \Drupal\social_post\Plugin\Field\FieldFormatter\CommentPostFormatter::loadThread()
- 8.4 modules/social_features/social_post/src/Plugin/Field/FieldFormatter/CommentPostFormatter.php \Drupal\social_post\Plugin\Field\FieldFormatter\CommentPostFormatter::loadThread()
- 8.5 modules/social_features/social_post/src/Plugin/Field/FieldFormatter/CommentPostFormatter.php \Drupal\social_post\Plugin\Field\FieldFormatter\CommentPostFormatter::loadThread()
- 8.6 modules/social_features/social_post/src/Plugin/Field/FieldFormatter/CommentPostFormatter.php \Drupal\social_post\Plugin\Field\FieldFormatter\CommentPostFormatter::loadThread()
- 8.7 modules/social_features/social_post/src/Plugin/Field/FieldFormatter/CommentPostFormatter.php \Drupal\social_post\Plugin\Field\FieldFormatter\CommentPostFormatter::loadThread()
- 10.3.x modules/social_features/social_post/src/Plugin/Field/FieldFormatter/CommentPostFormatter.php \Drupal\social_post\Plugin\Field\FieldFormatter\CommentPostFormatter::loadThread()
- 10.0.x modules/social_features/social_post/src/Plugin/Field/FieldFormatter/CommentPostFormatter.php \Drupal\social_post\Plugin\Field\FieldFormatter\CommentPostFormatter::loadThread()
- 10.1.x modules/social_features/social_post/src/Plugin/Field/FieldFormatter/CommentPostFormatter.php \Drupal\social_post\Plugin\Field\FieldFormatter\CommentPostFormatter::loadThread()
- 10.2.x modules/social_features/social_post/src/Plugin/Field/FieldFormatter/CommentPostFormatter.php \Drupal\social_post\Plugin\Field\FieldFormatter\CommentPostFormatter::loadThread()
See also
Drupal\comment\CommentStorage::loadThead()
1 call to CommentPostFormatter::loadThread()
- CommentPostFormatter::viewElements in modules/
social_features/ social_post/ src/ Plugin/ Field/ FieldFormatter/ CommentPostFormatter.php - Builds a renderable array for a field value.
1 method overrides CommentPostFormatter::loadThread()
- CommentPostActivityFormatter::loadThread in modules/
social_features/ social_post/ src/ Plugin/ Field/ FieldFormatter/ CommentPostActivityFormatter.php
File
- modules/
social_features/ social_post/ src/ Plugin/ Field/ FieldFormatter/ CommentPostFormatter.php, line 190
Class
- CommentPostFormatter
- Provides a post comment formatter.
Namespace
Drupal\social_post\Plugin\Field\FieldFormatterCode
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);
$comments_order = $this
->getSetting('order');
if (!$this->currentUser
->hasPermission('administer comments')) {
$query
->condition('c.status', CommentInterface::PUBLISHED);
}
if ($mode == CommentManagerInterface::COMMENT_MODE_FLAT) {
$query
->orderBy('c.cid', $comments_order);
}
else {
// See comment above. Analysis reveals that this doesn't cost too
// much. It scales much much better than having the whole comment
// structure.
$query
->addExpression('SUBSTRING(c.thread, 1, (LENGTH(c.thread) - 1))', 'torder');
$query
->orderBy('torder', $comments_order);
}
// Limit The number of results.
if ($comments_per_page) {
$query
->range(0, $comments_per_page);
}
$cids = $query
->execute()
->fetchCol();
$comments = [];
if ($cids) {
$comments = entity_load_multiple('comment', $cids);
}
return $comments;
}