You are here

protected function SocialCommentViewBuilder::alterBuild in Open Social 8.3

Same name and namespace in other branches
  1. 8.9 modules/social_features/social_comment/src/SocialCommentViewBuilder.php \Drupal\social_comment\SocialCommentViewBuilder::alterBuild()
  2. 8 modules/social_features/social_comment/src/SocialCommentViewBuilder.php \Drupal\social_comment\SocialCommentViewBuilder::alterBuild()
  3. 8.2 modules/social_features/social_comment/src/SocialCommentViewBuilder.php \Drupal\social_comment\SocialCommentViewBuilder::alterBuild()
  4. 8.4 modules/social_features/social_comment/src/SocialCommentViewBuilder.php \Drupal\social_comment\SocialCommentViewBuilder::alterBuild()
  5. 8.5 modules/social_features/social_comment/src/SocialCommentViewBuilder.php \Drupal\social_comment\SocialCommentViewBuilder::alterBuild()
  6. 8.6 modules/social_features/social_comment/src/SocialCommentViewBuilder.php \Drupal\social_comment\SocialCommentViewBuilder::alterBuild()
  7. 8.7 modules/social_features/social_comment/src/SocialCommentViewBuilder.php \Drupal\social_comment\SocialCommentViewBuilder::alterBuild()
  8. 8.8 modules/social_features/social_comment/src/SocialCommentViewBuilder.php \Drupal\social_comment\SocialCommentViewBuilder::alterBuild()
  9. 10.3.x modules/social_features/social_comment/src/SocialCommentViewBuilder.php \Drupal\social_comment\SocialCommentViewBuilder::alterBuild()
  10. 10.0.x modules/social_features/social_comment/src/SocialCommentViewBuilder.php \Drupal\social_comment\SocialCommentViewBuilder::alterBuild()
  11. 10.1.x modules/social_features/social_comment/src/SocialCommentViewBuilder.php \Drupal\social_comment\SocialCommentViewBuilder::alterBuild()
  12. 10.2.x modules/social_features/social_comment/src/SocialCommentViewBuilder.php \Drupal\social_comment\SocialCommentViewBuilder::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 CommentViewBuilder::alterBuild

File

modules/social_features/social_comment/src/SocialCommentViewBuilder.php, line 17

Class

SocialCommentViewBuilder
View builder handler for social comments.

Namespace

Drupal\social_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']) {
      if ($build['#comment_indent'] <= 0) {
        $prefix .= str_repeat('</div>', abs($build['#comment_indent']));
      }

      // We are in a thread of comments.
      if ($build['#comment_indent'] > 0) {
        $div_class = 'comments';

        // If the parent comment is unpublished, hide the thread for users
        // who may not see unpublished comments.
        if (!$comment
          ->getParentComment()
          ->isPublished() && !\Drupal::currentUser()
          ->hasPermission('administer comments')) {
          $div_class .= ' hidden';
        }
        $prefix .= "\n" . '<div class="' . $div_class . '">';
      }
    }

    // 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']);
    }

    // Need to display reply comments without indentation in activity items.
    $no_indent_view_modes = [
      'activity',
      'activity_comment',
    ];
    if (in_array($view_mode, $no_indent_view_modes)) {
      $build['#prefix'] = '';
      $build['#suffix'] = '';
    }
  }
}