You are here

public function TestController::saveHeartbeats in Heartbeat 8

1 string reference to 'TestController::saveHeartbeats'
heartbeat.routing.yml in ./heartbeat.routing.yml
heartbeat.routing.yml

File

src/Controller/TestController.php, line 65

Class

TestController
Class TestController.

Namespace

Drupal\heartbeat\Controller

Code

public function saveHeartbeats() {
  $heartbeats = $this->entityQuery
    ->get("heartbeat")
    ->execute();
  $data = array();
  foreach ($heartbeats as $hid) {
    $beat = $this->entityTypeManager
      ->getStorage("heartbeat")
      ->load($hid);
    $data[] = $beat;
  }
  $result = '';
  $result = file_put_contents("public://heartbeats.dat", serialize($data)) ? 'Saved Heartbeats' : 'Error saving heartbeats';
  return [
    '#type' => 'markup',
    '#markup' => $this
      ->t($result),
  ];
}