You are here

public function HeartbeatStreamController::createRoute in Heartbeat 8

Getroutes.

Return value

string Return Hello string.

File

src/Controller/HeartbeatStreamController.php, line 79

Class

HeartbeatStreamController
Class HeartbeatStreamController.

Namespace

Drupal\heartbeat\Controller

Code

public function createRoute($heartbeatStreamId) {
  $messages = array();
  $heartbeatTypes = array();
  $types = $this->heartbeatStreamService
    ->getTypesById($heartbeatStreamId);
  foreach ($types as $type) {
    if ($type != null && strlen($type
      ->getValue()['target_id']) > 1) {
      $heartbeatTypes[] = $type
        ->getValue()['target_id'];
    }
  }
  $heartbeats = $this->heartbeatService
    ->loadByTypes($heartbeatTypes);
  foreach ($heartbeats as $heartbeat) {

    //      $messages[] = $heartbeat->getMessage()->getValue()[0]['value'];
    $entity = $this->entityTypeManager
      ->getStorage('heartbeat')
      ->load($heartbeat
      ->id());
    $view_builder = $this->entityTypeManager
      ->getViewBuilder('heartbeat');
    $pre_render = $view_builder
      ->view($entity);
    $render_output = render($pre_render);
    $messages[] = $pre_render;
  }
  return [
    '#theme' => 'heartbeat_stream',
    '#messages' => $messages,
    '#attached' => array(
      'library' => 'heartbeat/heartbeat',
    ),
  ];
}