CommentViewBuilder::alterBuild

protected CommentViewBuilder::alterBuild(array &$build, EntityInterface $comment, EntityViewDisplayInterface $display, $view_mode)

Specific per-entity building.

Parameters

array $build: The render array that is being created.

\Drupal\Core\Entity\EntityInterface $entity: The entity to be prepared.

\Drupal\Core\Entity\Display\EntityViewDisplayInterface $display: The entity view display holding the display options configured for the entity components.

string $view_mode: The view mode that should be used to prepare the entity.

Overrides EntityViewBuilder::alterBuild

File

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

Class

CommentViewBuilder
View builder handler for comments.

Namespace

Drupal\comment

Code

protected function alterBuild(array &$build, EntityInterface $comment, EntityViewDisplayInterface $display, $view_mode) {
  parent::alterBuild($build, $comment, $display, $view_mode);
  if (empty($comment->in_preview)) {
    $prefix = '';

    // Add indentation div or close open divs as needed.
    if ($build['#comment_threaded']) {
      $prefix .= $build['#comment_indent'] <= 0 ? str_repeat('</div>', abs($build['#comment_indent'])) : "\n" . '<div class="indented">';
    }

    // Add anchor for each comment.
    $prefix .= "<a id=\"comment-{$comment->id()}\"></a>\n";
    $build['#prefix'] = $prefix;

    // Close all open divs.
    if (!empty($build['#comment_indent_final'])) {
      $build['#suffix'] = str_repeat('</div>', $build['#comment_indent_final']);
    }
  }
}
doc_Drupal
2016-10-29 08:51:23
Comments
Leave a Comment

Please login to continue.