' . t('About') . ''; $output .= '

' . t('Heartbeat for Drupal 8') . '

'; return $output; default: } } /** * Implements hook_theme(). */ function heartbeat_theme() { $theme = []; $theme['heartbeat'] = array( 'render element' => 'elements', 'file' => 'heartbeat.page.inc', 'template' => 'heartbeat', ); $theme['heartbeat_content_add_list'] = [ 'render element' => 'content', 'variables' => ['content' => NULL], 'file' => 'heartbeat.page.inc', ]; $theme['heartbeat_stream'] = [ 'variables' => array( 'messages' => NULL, 'zilla' => 2, ) ]; return $theme; } /** * Implements hook_theme_suggestions_HOOK(). */ function heartbeat_theme_suggestions_heartbeat(array $variables) { $suggestions = array(); $entity = $variables['elements']['#heartbeat']; $sanitized_view_mode = strtr($variables['elements']['#view_mode'], '.', '_'); $suggestions[] = 'heartbeat__' . $sanitized_view_mode; $suggestions[] = 'heartbeat__' . $entity->bundle(); $suggestions[] = 'heartbeat__' . $entity->bundle() . '__' . $sanitized_view_mode; $suggestions[] = 'heartbeat__' . $entity->id(); $suggestions[] = 'heartbeat__' . $entity->id() . '__' . $sanitized_view_mode; return $suggestions; } /** * Implements hook_entity_insert(). */ function heartbeat_entity_insert(EntityInterface $entity) { switch (true) { case $entity instanceof \Drupal\node\Entity\Node: $user = $entity->getOwner(); $media = HeartBeat::mediaFieldTypes($entity->getFields()); if ($entity->id() && $user->isAuthenticated()) { $heartbeatTypeService = \Drupal::service('heartbeat.heartbeattype'); $tokenService = \Drupal::service('token'); foreach ($heartbeatTypeService->getTypes() as $type) { $heartbeatTypeEntity = $heartbeatTypeService->load($type); $arguments = json_decode($heartbeatTypeEntity->getArguments()); foreach ($arguments as $key => $argument) { $variables[$key] = $argument; } $preparsedMessageString = strtr($heartbeatTypeEntity->getMessage(), $variables); $entities = array( 'node' => $entity, 'user' => $user, ); $heartbeatMessage = Heartbeat::buildMessage($tokenService, $preparsedMessageString, $entities, $media); // $translatedMessage = t($messageTemplate); $heartbeatActivity = Heartbeat::create([ 'type' => $heartbeatTypeEntity->id(), 'uid' => $user->id(), 'nid' => $entity->id(), 'name' => 'Dev Test', ]); $heartbeatActivity->setMessage($heartbeatMessage); $heartbeatActivity->save(); } } break; case $entity instanceof \Drupal\user\Entity\User: // $userService = \Drupal\User\Entity\user break; case $entity instanceof \Drupal\flag\Entity\Flag: break; } } function heartbeat_node_presave(NodeInterface $node) { $uid = $node->getOwnerId(); $stuffTOdo = null; } //TODO Add heartbeat language to Javascript //TODO Determine necessity of polling //Add