HeartbeatSubCommentBlock.php in Heartbeat 8
File
src/Plugin/Block/HeartbeatSubCommentBlock.php
View source
<?php
namespace Drupal\heartbeat\Plugin\Block;
use Drupal\Core\Block\BlockBase;
use Drupal\Core\Entity\EntityTypeManager;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Form\FormBuilder;
class HeartbeatSubCommentBlock extends BlockBase implements ContainerFactoryPluginInterface {
protected $form_builder;
protected $entityId;
protected $config;
protected $entityTypeManager;
public function __construct(array $configuration, $plugin_id, $plugin_definition, FormBuilder $form_builder, EntityTypeManager $entity_type_manager) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->form_builder = $form_builder;
$this->entityTypeManager = $entity_type_manager;
}
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('form_builder'), $container
->get('entity_type.manager'));
}
public function build() {
if ($this->entityTypeManager !== null) {
$comment = $this->entityTypeManager
->getStorage('comment')
->load(\Drupal::config('heartbeat_comment.settings')
->get('cid'));
return $this->form_builder
->getForm('\\Drupal\\heartbeat\\Form\\HeartbeatSubCommentForm', $comment);
}
return null;
}
public function setEntityId($id) {
$this->entityId = $id;
}
}