protected function CommentViewBuilder::alterBuild in Drupal 10
Same name and namespace in other branches
- 8 core/modules/comment/src/CommentViewBuilder.php \Drupal\comment\CommentViewBuilder::alterBuild()
- 9 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 190
Class
- CommentViewBuilder
- View builder handler 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">';
}
$build['#prefix'] = $prefix;
// Close all open divs.
if (!empty($build['#comment_indent_final'])) {
$build['#suffix'] = str_repeat('</div>', $build['#comment_indent_final']);
}
}
}