Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. CommentViewBuilder.php

function CommentViewBuilder::alterBuild

Overrides EntityViewBuilder::alterBuild

File

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

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">';
        }
        $build['#prefix'] = $prefix;
        // Close all open divs.
        if (!empty($build['#comment_indent_final'])) {
            $build['#suffix'] = str_repeat('</div>', $build['#comment_indent_final']);
        }
    }
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal