فهرست منبع

Heartbeat saving by bundle is more strict
HeartbeatService new method: loadByTypes([HeartbeatTypes ids])

logicp 7 سال پیش
والد
کامیت
fe2599c416
3فایلهای تغییر یافته به همراه26 افزوده شده و 20 حذف شده
  1. 14 11
      heartbeat.module
  2. 8 9
      src/Controller/HeartbeatStreamController.php
  3. 4 0
      src/HeartbeatService.php

+ 14 - 11
heartbeat.module

@@ -130,22 +130,25 @@ function heartbeat_entity_insert(EntityInterface $entity) {
               $heartbeatActivity->setMessage($heartbeatMessage);
               $heartbeatActivity->save();
               continue;
-            }
+            } else if ($heartbeatTypeEntity->getBundle() === null || trim($heartbeatTypeEntity->getBundle()) === '') {
 
-            $heartbeatMessage = Heartbeat::buildMessage($tokenService, $preparsedMessageString, $entities, $entity->getEntityTypeId(), $media);
+              $heartbeatMessage = Heartbeat::buildMessage($tokenService, $preparsedMessageString, $entities, $entity->getEntityTypeId(), $media);
 
-            //      $translatedMessage = t($messageTemplate);
+              //      $translatedMessage = t($messageTemplate);
 
-            $heartbeatActivity = Heartbeat::create([
-              'type' => $heartbeatTypeEntity->id(),
-              'uid' => $user->id(),
-              'nid' => $entity->id(),
-              'name' => 'Dev Test',
-            ]);
+              $heartbeatActivity = Heartbeat::create([
+                'type' => $heartbeatTypeEntity->id(),
+                'uid' => $user->id(),
+                'nid' => $entity->id(),
+                'name' => 'Dev Test',
+              ]);
 
-            $heartbeatActivity->setMessage($heartbeatMessage);
-            $heartbeatActivity->save();
+              $heartbeatActivity->setMessage($heartbeatMessage);
+              $heartbeatActivity->save();
 
+            } else {
+              continue;
+            }
           }
         }
       }

+ 8 - 9
src/Controller/HeartbeatStreamController.php

@@ -79,19 +79,18 @@ class HeartbeatStreamController extends ControllerBase {
   public function createRoute($heartbeatStreamId) {
 
     $messages = array();
+    $heartbeatTypes = array();
     $types = $this->heartbeatStreamService->getTypesById($heartbeatStreamId);
     foreach ($types as $type) {
-      if ($type != null) {
-
-        $heartbeatType = $type->getValue();
-
-        $heartbeats = $this->heartbeatService->loadByType($heartbeatType);
-
-        foreach($heartbeats as $heartbeat) {
-          $messages[] = $heartbeat->getMessage()->getValue()[0]['value'];
-        }
+      if ($type != null && strlen($type->getValue()['target_id']) > 1) {
+        $heartbeatTypes[] = $type->getValue()['target_id'];
       }
     }
+    $heartbeats = $this->heartbeatService->loadByTypes($heartbeatTypes);
+
+    foreach($heartbeats as $heartbeat) {
+      $messages[] = $heartbeat->getMessage()->getValue()[0]['value'];
+    }
     return [
       '#theme' => 'heartbeat_stream',
       '#messages' => $messages,

+ 4 - 0
src/HeartbeatService.php

@@ -48,5 +48,9 @@ class HeartbeatService {
   public function loadByType($type) {
     return $this->entityTypeManager->getStorage("heartbeat")->loadMultiple($this->entityQuery->get('heartbeat')->condition('type', $type)->execute());
   }
+
+  public function loadByTypes($types) {
+    return $this->entityTypeManager->getStorage("heartbeat")->loadMultiple($this->entityQuery->get('heartbeat')->condition('type', $types, 'IN')->sort('created', 'DESC')->execute());
+  }
 }