You are here

protected function CommentViewBuilder::getBuildDefaults in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/comment/src/CommentViewBuilder.php \Drupal\comment\CommentViewBuilder::getBuildDefaults()

Provides entity-specific defaults to the build process.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity for which the defaults should be provided.

string $view_mode: The view mode that should be used.

Return value

array

Overrides EntityViewBuilder::getBuildDefaults

File

core/modules/comment/src/CommentViewBuilder.php, line 64
Contains \Drupal\comment\CommentViewBuilder.

Class

CommentViewBuilder
Render controller 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().
  $build['#comment_threaded'] = $entity
    ->getCommentedEntity()
    ->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;
}