function CommentViewBuilder::getBuildDefaults

Same name in other branches
  1. 9 core/modules/comment/src/CommentViewBuilder.php \Drupal\comment\CommentViewBuilder::getBuildDefaults()
  2. 8.9.x core/modules/comment/src/CommentViewBuilder.php \Drupal\comment\CommentViewBuilder::getBuildDefaults()
  3. 10 core/modules/comment/src/CommentViewBuilder.php \Drupal\comment\CommentViewBuilder::getBuildDefaults()

Overrides EntityViewBuilder::getBuildDefaults

File

core/modules/comment/src/CommentViewBuilder.php, line 78

Class

CommentViewBuilder
View builder handler for comments.

Namespace

Drupal\comment

Code

protected function getBuildDefaults(EntityInterface $entity, $view_mode) {
    $build = parent::getBuildDefaults($entity, $view_mode);
    
    /** @var \Drupal\comment\CommentInterface $entity */
    // Store a threading field setting to use later in self::buildComponents().
    $commented_entity = $entity->getCommentedEntity();
    $build['#comment_threaded'] = is_null($commented_entity) || $commented_entity->getFieldDefinition($entity->getFieldName())
        ->getSetting('default_mode') === CommentManagerInterface::COMMENT_MODE_THREADED;
    // If threading is enabled, don't render cache individual comments, but do
    // keep the cacheability metadata, so it can bubble up.
    if ($build['#comment_threaded']) {
        unset($build['#cache']['keys']);
    }
    return $build;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.