|
@@ -3,9 +3,11 @@
|
|
|
namespace Drupal\heartbeat\Plugin\Block;
|
|
|
|
|
|
use Drupal\Core\Block\BlockBase;
|
|
|
+use Drupal\Core\Config\ConfigFactory;
|
|
|
use Drupal\Core\Entity\EntityTypeManager;
|
|
|
use Drupal\Core\Form\FormBuilder;
|
|
|
use Drupal\flag\FlagService;
|
|
|
+use Drupal\comment\Entity\Comment;
|
|
|
use Drupal\User\Entity\User;
|
|
|
use Drupal\Flag\Entity\Flag;
|
|
|
use Drupal\Core\Datetime\DateFormatter;
|
|
@@ -16,6 +18,7 @@ use Drupal\Core\Database\Database;
|
|
|
use Drupal\heartbeat\HeartbeatTypeServices;
|
|
|
use Drupal\heartbeat\HeartbeatStreamServices;
|
|
|
use Drupal\heartbeat\HeartbeatService;
|
|
|
+use Drupal\heartbeat\Plugin\Block\HeartbeatCommentBlock;
|
|
|
|
|
|
//* deriver = "Drupal\heartbeat\Plugin\Derivative\HeartbeatBlockDeriver
|
|
|
|
|
@@ -55,6 +58,9 @@ class HeartbeatBlock extends BlockBase implements ContainerFactoryPluginInterfac
|
|
|
protected $flagService;
|
|
|
|
|
|
protected $formBuilder;
|
|
|
+
|
|
|
+ protected $configFactory;
|
|
|
+
|
|
|
/**
|
|
|
* Construct.
|
|
|
*
|
|
@@ -71,7 +77,7 @@ class HeartbeatBlock extends BlockBase implements ContainerFactoryPluginInterfac
|
|
|
$plugin_definition,
|
|
|
HeartbeatTypeServices $heartbeat_heartbeattype,
|
|
|
HeartbeatStreamServices $heartbeatstream,
|
|
|
- HeartbeatService $heartbeat, EntityTypeManager $entity_type_manager, DateFormatter $date_formatter, FlagService $flag_service, FormBuilder $form_builder
|
|
|
+ HeartbeatService $heartbeat, EntityTypeManager $entity_type_manager, DateFormatter $date_formatter, FlagService $flag_service, FormBuilder $form_builder, ConfigFactory $configFactory
|
|
|
) {
|
|
|
parent::__construct($configuration, $plugin_id, $plugin_definition);
|
|
|
$this->heartbeatTypeServices = $heartbeat_heartbeattype;
|
|
@@ -81,6 +87,7 @@ class HeartbeatBlock extends BlockBase implements ContainerFactoryPluginInterfac
|
|
|
$this->dateFormatter = $date_formatter;
|
|
|
$this->flagService = $flag_service;
|
|
|
$this->formBuilder = $form_builder;
|
|
|
+ $this->configFactory = $configFactory;
|
|
|
}
|
|
|
/**
|
|
|
* {@inheritdoc}
|
|
@@ -96,7 +103,8 @@ class HeartbeatBlock extends BlockBase implements ContainerFactoryPluginInterfac
|
|
|
$container->get('entity_type.manager'),
|
|
|
$container->get('date.formatter'),
|
|
|
$container->get('flag'),
|
|
|
- $container->get('form_builder')
|
|
|
+ $container->get('form_builder'),
|
|
|
+ $container->get('config.factory')
|
|
|
);
|
|
|
}
|
|
|
|
|
@@ -175,40 +183,69 @@ class HeartbeatBlock extends BlockBase implements ContainerFactoryPluginInterfac
|
|
|
$profilePic = $user->get('user_picture')->getValue()[0]['target_id'];
|
|
|
}
|
|
|
|
|
|
-// $commentForm = $this->formBuilder->getForm('Drupal\comment\CommentForm', $heartbeat);
|
|
|
-
|
|
|
-// $flagRenderable = $flagLink->toRenderable();
|
|
|
-
|
|
|
- if (null === $profilePic) {
|
|
|
+ if (NULL === $profilePic) {
|
|
|
$profilePic = 86;
|
|
|
}
|
|
|
|
|
|
$pic = File::load($profilePic);
|
|
|
|
|
|
- if ($pic !== null) {
|
|
|
- $style = $this->entityTypeManager->getStorage('image_style')->load('thumbnail');
|
|
|
-
|
|
|
+ if ($pic !== NULL) {
|
|
|
+ $style = $this->entityTypeManager->getStorage('image_style')
|
|
|
+ ->load('thumbnail');
|
|
|
$rendered = $style->buildUrl($pic->getFileUri());
|
|
|
}
|
|
|
|
|
|
+ $cids = \Drupal::entityQuery('comment')
|
|
|
+ ->condition('entity_id', $heartbeat->id())
|
|
|
+ ->condition('entity_type', 'heartbeat')
|
|
|
+ ->sort('cid', 'DESC')
|
|
|
+ ->execute();
|
|
|
+
|
|
|
+ $comments = [];
|
|
|
|
|
|
-//TODO GET ACTION AND APPEND TO CLASSES IN FLAG WRAPPER
|
|
|
+ foreach($cids as $cid) {
|
|
|
|
|
|
+// $comment = $this->entityTypeManager->getStorage('comment')->load($cid);
|
|
|
+ $comment = Comment::load($cid);
|
|
|
+// $comment->delete();
|
|
|
|
|
|
+ $comments[] = $comment->get('comment_body')->value;
|
|
|
+ }
|
|
|
+
|
|
|
+// $heartbeatCommentBlock = \Drupal\block\Entity\Block::load('heartbeatcommentblock');
|
|
|
+// $commentForm = $this->entityTypeManager->getViewBuilder('block')
|
|
|
+// ->view($heartbeatCommentBlock);
|
|
|
|
|
|
+ $form = \Drupal::service('form_builder')->getForm('\Drupal\heartbeat\Form\HeartbeatCommentForm', $heartbeat);
|
|
|
|
|
|
+ $likeFlag = $this->flagService->getFlagById('heartbeat_like');
|
|
|
|
|
|
+ $flagKey = 'flag_' . $likeFlag->id();
|
|
|
+ $flagData = [
|
|
|
+ '#lazy_builder' => ['flag.link_builder:build', [
|
|
|
+ $heartbeat->getEntityTypeId(),
|
|
|
+ $heartbeat->id(),
|
|
|
+ $likeFlag->id(),
|
|
|
+ ]],
|
|
|
+ '#create_placeholder' => TRUE,
|
|
|
+ ];
|
|
|
|
|
|
$messages[] = array('heartbeat' => $heartbeat->getMessage()->getValue()[0]['value'],
|
|
|
'userPicture' => $rendered,
|
|
|
'userId' => $user->id(),
|
|
|
'timeAgo' => $timeago,
|
|
|
'id' => $heartbeat->id(),
|
|
|
-// 'friendFlag' => $flagUrl,
|
|
|
-// 'friendFlagText' => $flagText,
|
|
|
-// 'flagId' => $flag->id(),
|
|
|
'user' => $userView,
|
|
|
-// 'commentForm' => $commentForm
|
|
|
+ 'commentForm' => $form,
|
|
|
+ 'comments' => $comments,
|
|
|
+ 'likeFlag' => [$flagKey => $flagData],
|
|
|
);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+/******************************
|
|
|
+ * *****FOR COMMENT FEED*******
|
|
|
+ * *****ON EACH HEARTBEAT******
|
|
|
+ * ****************************/
|
|
|
+
|