Browse Source

Heartbeat -> updated static parsing method for greater functionality/maintainability

logicp 7 years ago
parent
commit
29f693762a
2 changed files with 14 additions and 8 deletions
  1. 9 5
      heartbeat.module
  2. 5 3
      src/Entity/Heartbeat.php

+ 9 - 5
heartbeat.module

@@ -108,17 +108,21 @@ if ($entity instanceof \Drupal\node\Entity\Node) {
       }
 
       $preparsedMessageString = strtr($heartbeatTypeEntity->getMessage(), $variables);
-      $replacedMessageString = $tokenService->replace($preparsedMessageString, array('node' => $entity, 'user' => $user));
 
-      $messageTemplate = Heartbeat::buildMessage($heartbeatTypeEntity, $media);
+      $entities = array(
+        'node' => $entity,
+        'user' => $user,
+      );
+
+      $messageTemplate = Heartbeat::buildMessage($tokenService, $preparsedMessageString, $entities, $media);
 
 //      $translatedMessage = t($messageTemplate);
 
       $heartbeatMarkup = Heartbeat::parseMessage($messageTemplate, $variables);
 
-//      $heartbeatActivity = new Heartbeat();
-//      $heartbeatActivity->setName();
-//      $heartbeatActivity->save();
+      $heartbeatActivity = new Heartbeat();
+      $heartbeatActivity->setName();
+      $heartbeatActivity->save();
 
 
     }

+ 5 - 3
src/Entity/Heartbeat.php

@@ -375,11 +375,11 @@ class Heartbeat extends RevisionableContentEntityBase implements HeartbeatInterf
    * @param null $mediaData
    * @return null|string
    */
-  public static function buildMessage(HeartbeatType $heartbeatType, $mediaData = NULL) {
+  public static function buildMessage(\Drupal\token\Token $tokenService, $preparsedMessage, $entities = NULL, $mediaData = NULL) {
 //!username has added !node_type !node_title. <a href="/node/"><img src="/sites/default/files/!node_image"/></a>
-
+    $parsedMessage = $tokenService->replace($preparsedMessage . '<a href="/node/[node:nid]">', $entities);
     /** @noinspection NestedTernaryOperatorInspection */
-    $message = $heartbeatType->get('message') . '<a href="/node/!nid">';
+    $message = $parsedMessage;
     $message .= $mediaData ? self::buildMediaMarkup($mediaData) : '';
     $message .= '</a>';
 
@@ -399,6 +399,8 @@ class Heartbeat extends RevisionableContentEntityBase implements HeartbeatInterf
   }
 
   private static function mediaTag($type, $filePath) {
+    //TODO put this into new method
+    if ($type == 'image') { $type = 'img';}
     return '<'. $type . ' src="' . $filePath . '" / >';
   }