protected function CommentViewBuilder::alterBuild in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/comment/src/CommentViewBuilder.php \Drupal\comment\CommentViewBuilder::alterBuild()
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 168 - Contains \Drupal\comment\CommentViewBuilder.
Class
- CommentViewBuilder
- Render controller for comments.
Namespace
Drupal\commentCode
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']);
}
}
}