123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- <?php
- use \Drupal\Core\Extension\ModuleHandler;
- /**
- * Prepares a heartbeat stream
- * @param $stream_name the name of the stream
- */
- function heartbeat_stream($stream_name, $page = 0, $account = NULL) {
- static $streams;
- try {
- if (!isset($streams[$stream_name])) {
- //Load configuration object for the stream
- $streamConfig = heartbeat_stream_config_load($stream_name);
- //Load the stream if access is permitted
- if (_heartbeat_stream_has_access($streamConfig)) {
- $heartbeatStream = HeartbeatStreamFactory::getStream($streamConfig, $page, $account);
- //Add settings that need to be set for each stream
- //TODO equivalent drupal_add_js to attach streamconfig messages to the drupalSettings object
- /*
- * drupal_add_js(array('heartbeatPollNewerMessages' => array($streamConfig->class => $streamConfig->poll_messages)), 'setting');
- * drupal_add_js(array('heartbeatPollTypes' => array($streamConfig->class => $streamConfig->poll_messages_type)), 'setting');
- *
- *
- */
- //Give other modules a chance to take action when stream is loaded
- ModuleHandler::invokeAll('heartbeat_stream_load', $heartbeatStream);
- if ($heartbeatStream instanceof HeartbeatStream && !$heartbeatStream->hasErrors()) {
- $streams[$stream_name] = $heartbeatStream;
- } else {
- $streams[$stream_name] = FALSE;
- }
- } else {
- $streams[$stream_name] = FALSE;
- }
- }
- } catch (HeartbeatInvalidStreamException $he) {
- $errorMessage = $he->getMessage();
- drupal_set_message($errorMessage);
- \Drupal::logger('HeartbeatDEBUG')->error('Error message: %errMsg', array(
- '%errMsg' => $errorMessage
- ));
- }
- return $streams[$stream_name];
- }
- /*
- * Builds a heartbeat stream in the StreamObject
- */
- function heartbeat_stream_build(HeartbeatStream &$heartbeatStream) {
- //Load messages
- $messages = $heartbeatStream->execute();
- }
- /*
- * Builds a stream from Views Results
- */
- function heartbeat_stream_views_build(HeartbeatStream &$heartbeatStream, $view_mode = NULL) {
- if (isset($view_mode)) {
- $heartbeatStream->setViewMode($view_mode);
- }
- $build = $heartbeatStream->render();
- return $build;
- }
|