public function CommentNodeFormatter::loadThread in Open Social 8.4
Same name and namespace in other branches
- 8.9 modules/social_features/social_core/src/Plugin/Field/FieldFormatter/CommentNodeFormatter.php \Drupal\social_core\Plugin\Field\FieldFormatter\CommentNodeFormatter::loadThread()
- 8 modules/social_features/social_core/src/Plugin/Field/FieldFormatter/CommentNodeFormatter.php \Drupal\social_core\Plugin\Field\FieldFormatter\CommentNodeFormatter::loadThread()
- 8.2 modules/social_features/social_core/src/Plugin/Field/FieldFormatter/CommentNodeFormatter.php \Drupal\social_core\Plugin\Field\FieldFormatter\CommentNodeFormatter::loadThread()
- 8.3 modules/social_features/social_core/src/Plugin/Field/FieldFormatter/CommentNodeFormatter.php \Drupal\social_core\Plugin\Field\FieldFormatter\CommentNodeFormatter::loadThread()
- 8.5 modules/social_features/social_core/src/Plugin/Field/FieldFormatter/CommentNodeFormatter.php \Drupal\social_core\Plugin\Field\FieldFormatter\CommentNodeFormatter::loadThread()
- 8.6 modules/social_features/social_core/src/Plugin/Field/FieldFormatter/CommentNodeFormatter.php \Drupal\social_core\Plugin\Field\FieldFormatter\CommentNodeFormatter::loadThread()
- 8.7 modules/social_features/social_core/src/Plugin/Field/FieldFormatter/CommentNodeFormatter.php \Drupal\social_core\Plugin\Field\FieldFormatter\CommentNodeFormatter::loadThread()
- 8.8 modules/social_features/social_core/src/Plugin/Field/FieldFormatter/CommentNodeFormatter.php \Drupal\social_core\Plugin\Field\FieldFormatter\CommentNodeFormatter::loadThread()
- 10.3.x modules/social_features/social_core/src/Plugin/Field/FieldFormatter/CommentNodeFormatter.php \Drupal\social_core\Plugin\Field\FieldFormatter\CommentNodeFormatter::loadThread()
- 10.0.x modules/social_features/social_core/src/Plugin/Field/FieldFormatter/CommentNodeFormatter.php \Drupal\social_core\Plugin\Field\FieldFormatter\CommentNodeFormatter::loadThread()
- 10.1.x modules/social_features/social_core/src/Plugin/Field/FieldFormatter/CommentNodeFormatter.php \Drupal\social_core\Plugin\Field\FieldFormatter\CommentNodeFormatter::loadThread()
- 10.2.x modules/social_features/social_core/src/Plugin/Field/FieldFormatter/CommentNodeFormatter.php \Drupal\social_core\Plugin\Field\FieldFormatter\CommentNodeFormatter::loadThread()
See also
Drupal\comment\CommentStorage::loadThead()
1 call to CommentNodeFormatter::loadThread()
- CommentNodeFormatter::viewElements in modules/
social_features/ social_core/ src/ Plugin/ Field/ FieldFormatter/ CommentNodeFormatter.php - Builds a renderable array for a field value.
File
- modules/
social_features/ social_core/ src/ Plugin/ Field/ FieldFormatter/ CommentNodeFormatter.php, line 196
Class
- CommentNodeFormatter
- Provides a node comment formatter.
Namespace
Drupal\social_core\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)
->isNull('c.pid')
->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);
}
if ($mode == CommentManagerInterface::COMMENT_MODE_FLAT) {
$query
->orderBy('c.cid', 'DESC');
}
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', 'DESC');
}
// 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;
}