|
@@ -74,68 +74,68 @@ function heartbeat_theme_suggestions_heartbeat(array $variables) {
|
|
|
return $suggestions;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* Implements hook_entity_insert().
|
|
|
*/
|
|
|
function heartbeat_entity_insert(EntityInterface $entity) {
|
|
|
|
|
|
- if ($entity instanceof \Drupal\node\Entity\Node) {
|
|
|
+ switch (true) {
|
|
|
+ case $entity instanceof \Drupal\node\Entity\Node:
|
|
|
|
|
|
- $nid = $entity->id();
|
|
|
- $user = $entity->getOwner();
|
|
|
- $type = $entity->getEntityTypeId();
|
|
|
- $media = HeartBeat::mediaFieldTypes($entity->getFields());
|
|
|
+ $user = $entity->getOwner();
|
|
|
+ $media = HeartBeat::mediaFieldTypes($entity->getFields());
|
|
|
|
|
|
- /** @noinspection NestedTernaryOperatorInspection */
|
|
|
- /** @noinspection ArrayCastingEquivalentInspection */
|
|
|
- // $variables = array(
|
|
|
- // '!nid' => $nid,
|
|
|
- // '!entityType' => $type,
|
|
|
- // '!uid' => $user->id(),
|
|
|
- // '!user' => $user->getAccountName(),
|
|
|
- // 'media' => $media,
|
|
|
- // );
|
|
|
+ if ($entity->id() && $user->isAuthenticated()) {
|
|
|
|
|
|
+ $heartbeatTypeService = \Drupal::service('heartbeat.heartbeattype');
|
|
|
+ $tokenService = \Drupal::service('token');
|
|
|
|
|
|
- if ($entity->id() && $user->isAuthenticated()) {
|
|
|
+ foreach ($heartbeatTypeService->getTypes() as $type) {
|
|
|
|
|
|
- $heartbeatTypeService = \Drupal::service('heartbeat.heartbeattype');
|
|
|
- $tokenService = \Drupal::service('token');
|
|
|
+ $heartbeatTypeEntity = $heartbeatTypeService->load($type);
|
|
|
+ $arguments = json_decode($heartbeatTypeEntity->getArguments());
|
|
|
|
|
|
- foreach ($heartbeatTypeService->getTypes() as $type) {
|
|
|
+ foreach ($arguments as $key => $argument) {
|
|
|
+ $variables[$key] = $argument;
|
|
|
+ }
|
|
|
|
|
|
- $heartbeatTypeEntity = $heartbeatTypeService->load($type);
|
|
|
- $arguments = json_decode($heartbeatTypeEntity->getArguments());
|
|
|
+ $preparsedMessageString = strtr($heartbeatTypeEntity->getMessage(), $variables);
|
|
|
|
|
|
- foreach ($arguments as $key => $argument) {
|
|
|
- $variables[$key] = $argument;
|
|
|
- }
|
|
|
+ $entities = array(
|
|
|
+ 'node' => $entity,
|
|
|
+ 'user' => $user,
|
|
|
+ );
|
|
|
|
|
|
- $preparsedMessageString = strtr($heartbeatTypeEntity->getMessage(), $variables);
|
|
|
+ $heartbeatMessage = Heartbeat::buildMessage($tokenService, $preparsedMessageString, $entities, $media);
|
|
|
|
|
|
- $entities = array(
|
|
|
- 'node' => $entity,
|
|
|
- 'user' => $user,
|
|
|
- );
|
|
|
+ // $translatedMessage = t($messageTemplate);
|
|
|
|
|
|
- $heartbeatMessage = Heartbeat::buildMessage($tokenService, $preparsedMessageString, $entities, $media);
|
|
|
+ $heartbeatActivity = Heartbeat::create([
|
|
|
+ 'type' => $heartbeatTypeEntity->id(),
|
|
|
+ 'uid' => $user->id(),
|
|
|
+ 'nid' => $entity->id(),
|
|
|
+ 'name' => 'Dev Test',
|
|
|
+ ]);
|
|
|
|
|
|
- // $translatedMessage = t($messageTemplate);
|
|
|
+ $heartbeatActivity->setMessage($heartbeatMessage);
|
|
|
+ $heartbeatActivity->save();
|
|
|
|
|
|
- $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) {
|