Browse Source

adding dependencies
adding better error handling

logicp 7 years ago
parent
commit
6ff96bb0cb
3 changed files with 20 additions and 5 deletions
  1. 3 0
      heartbeat.info.yml
  2. 3 1
      src/HeartbeatStreamServices.php
  3. 14 4
      src/Plugin/Block/HeartbeatBlock.php

+ 3 - 0
heartbeat.info.yml

@@ -3,3 +3,6 @@ type: module
 description: Heartbeat for Drupal 8
 core: 8.x
 package: Heartbeat
+dependencies:
+  - token
+  - flag

+ 3 - 1
src/HeartbeatStreamServices.php

@@ -102,7 +102,9 @@ class HeartbeatStreamServices {
 
     foreach ($this->getAllStreams() as $stream) {
       foreach ($stream->getTypes() as $type) {
-        $types[] = $type;
+        if (strlen($type->getValue()[0]['target_id']) > 1) {
+          $types[] = $type;
+        }
       }
     }
     return $this->entityTypeManager->getStorage('heartbeat')->loadMultiple($this->entityQuery->get('heartbeat')->condition('status', 1)->condition('type', array_column($types, 'target_id'), 'IN')->sort('created', 'DESC')->execute());

+ 14 - 4
src/Plugin/Block/HeartbeatBlock.php

@@ -153,10 +153,20 @@ class HeartbeatBlock extends BlockBase implements ContainerFactoryPluginInterfac
 
       $timeago = $this->dateFormatter->formatInterval(REQUEST_TIME - $heartbeat->getCreatedTime());
       $user = $heartbeat->getOwner();
-      $profilePic = $user->get('user_picture');
-      $style = $this->entityTypeManager->getStorage('image_style')->load('thumbnail');
-      $pic = File::load($profilePic->getValue()[0]['target_id'])->getFileUri();
-      $rendered = $style->buildUrl($pic);
+      $profilePic = $user->get('user_picture')->getValue()[0]['target_id'];
+      if ($profilePic === null) {
+        $profilePic = 86;
+      }
+      $pic2 = $this->entityTypeManager->getStorage('file')->load($profilePic);
+      $pic = File::load($profilePic);
+
+      if ($pic !== null) {
+        $style = $this->entityTypeManager->getStorage('image_style')->load('thumbnail');
+
+        $rendered = $style->buildUrl($pic->getFileUri());
+
+      }
+
       $messages[] = array('heartbeat' => $heartbeat->getMessage()->getValue()[0]['value'],
         'userPicture' => $rendered,
         'userId' => $user->id(),