' . 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', ]; 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) { if ($entity instanceof \Drupal\node\Entity\Node) { $nid = $entity->id(); $user = $entity->getOwner(); $type = $entity->getEntityTypeId(); $media = HeartBeat::mediaFieldTypes($entity->getFields()); /** @noinspection NestedTernaryOperatorInspection */ /** @noinspection ArrayCastingEquivalentInspection */ $variables = array( '!nid' => $nid, '!entityType' => $type, '!uid' => $user->id(), '!user' => $user->getAccountName(), 'media' => $media, ); } if ($nid) { $heartbeatTypeService = \Drupal::service('heartbeat.heartbeattype'); foreach ($heartbeatTypeService->getTypes() as $type) { $heartbeatTypeEntity = $heartbeatTypeService->load($type); $messageTemplate = Heartbeat::buildMessage($heartbeatTypeEntity, $media); // $translatedMessage = t($messageTemplate); $heartbeatMarkup = Heartbeat::parseMessage($messageTemplate, $variables); // $heartbeatActivity = new Heartbeat(); // $heartbeatActivity->setName(); // $heartbeatActivity->save(); } } } function heartbeat_node_presave(NodeInterface $node) { $uid = $node->getOwnerId(); $stuffTOdo = null; } //TODO Add heartbeat language to Javascript //TODO Determine necessity of polling //Add