You are here

public static function HeartbeatBlock::renderOneHeartbeat in Heartbeat 8

1 call to HeartbeatBlock::renderOneHeartbeat()
StatusForm::statusAjaxSubmit in modules/statusmessage/src/Form/StatusForm.php

File

src/Plugin/Block/HeartbeatBlock.php, line 324

Class

HeartbeatBlock
Provides a 'HeartbeatBlock' block.

Namespace

Drupal\heartbeat\Plugin\Block

Code

public static function renderOneHeartbeat(Heartbeat $heartbeat) {
  $timeago = 'Just now';
  $user = $heartbeat
    ->getOwner();
  $userView = user_view($user, 'compact');
  $userPic = $user
    ->get('user_picture')
    ->getValue();
  if (!empty($userPic)) {
    $profilePic = $userPic[0]['target_id'];
  }
  if (NULL === $profilePic) {
    $profilePic = 86;
  }
  $pic = File::load($profilePic);
  if ($pic !== NULL) {
    $style = \Drupal::entityTypeManager()
      ->getStorage('image_style')
      ->load('thumbnail');
    $rendered = $style
      ->buildUrl($pic
      ->getFileUri());
  }
  $flagService = \Drupal::service('flag');
  $form = \Drupal::service('form_builder')
    ->getForm('\\Drupal\\heartbeat\\Form\\HeartbeatCommentForm', $heartbeat);
  return '<div class="heartbeat-message" id="heartbeat-' . $heartbeat
    ->id() . '">
      <div class="heartbeat-message-wrap">
        <div class="heartbeat-owner">
          <a href="/user/' . $user
    ->id() . '"><img src="' . $rendered . '" />
            ' . $user
    ->getAccountName() . '
          </a>
          ' . \Drupal::service('renderer')
    ->render($userView)
    ->__toString() . '
          <div class="time-ago"> . ' . $timeago . '</div>
        </div>
        <div class="heartbeat-content hid-' . $heartbeat
    ->id() . '">
        ' . $heartbeat
    ->getMessage()
    ->getValue()[0]['value'] . '
        </div>
      </div>
      <div class="heartbeat-interaction-wrap">
        <div class="heartbeat-like">
           ' . \Drupal::service('renderer')
    ->renderplain(Heartbeat::flagAjaxBuilder('heartbeat_like', $heartbeat, $flagService))
    ->__toString() . '
        </div>
        <div class="heartbeat-unlike">
          ' . \Drupal::service('renderer')
    ->renderplain(Heartbeat::flagAjaxBuilder('heartbeat_unlike', $heartbeat, $flagService))
    ->__toString() . '
        </div>
        <div class="heartbeat-comment-button">
          Comment
        </div>
        <div class="heartbeat-comment" id="comment-' . $heartbeat
    ->id() . '">
        ' . \Drupal::service('renderer')
    ->renderplain($form)
    ->__toString() . '
        <div class="heartbeat-comments"></div>
        </div>
      </div>
    </div>';
}