You are here

public function HeartbeatStreamServices::createStreamByType in Heartbeat 8

File

src/HeartbeatStreamServices.php, line 166

Class

HeartbeatStreamServices
Class HeartbeatStreamServices.

Namespace

Drupal\heartbeat

Code

public function createStreamByType($type) {
  $stream = $this->entityTypeManager
    ->getStorage('heartbeat_stream')
    ->load(array_values($this
    ->loadStream($type))[0]);
  if ($stream !== null) {
    $types = array();
    foreach ($stream
      ->getTypes() as $heartbeatType) {
      $value = $heartbeatType
        ->getValue()['target_id'];
      if ($value !== "0") {
        $types[] = $value;
      }
    }
    $beats = $this->entityTypeManager
      ->getStorage('heartbeat')
      ->loadMultiple($this->entityQuery
      ->get('heartbeat')
      ->condition('status', 1)
      ->condition('type', $types, 'IN')
      ->sort('created', 'DESC')
      ->range(0, 25)
      ->execute());
    if (count($beats) > 0) {
      $this->lastId = call_user_func('end', array_keys($beats));
      $this->configFactory
        ->getEditable('heartbeat_update_feed.settings')
        ->set('lastId', $this->lastId)
        ->set('update', false)
        ->set('timestamp', array_values($beats)[0]
        ->getRevisionCreationTime())
        ->save();
      return $beats;
    }
  }
  return null;
}