Commit 13e4f314 authored by xjm's avatar xjm

Issue #2471218 by amateescu, Wim Leers: Dummy comment entity necessary for...

Issue #2471218 by amateescu, Wim Leers: Dummy comment entity necessary for building comment form is expensive to build
parent 7e36f27f
......@@ -15,7 +15,6 @@
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Url;
use Drupal\Core\Render\Renderer;
use Drupal\field\Entity\FieldStorageConfig;
/**
* Defines a service for comment post render cache callbacks.
......@@ -99,19 +98,17 @@ public function __construct(EntityManagerInterface $entity_manager, EntityFormBu
* - entity_type: an entity type
* - entity_id: an entity ID
* - field_name: a comment field name
* - comment_type: the comment type
*
* @return array
* A renderable array containing the comment form.
*/
public function renderForm(array $element, array $context) {
$field_name = $context['field_name'];
$entity = $this->entityManager->getStorage($context['entity_type'])->load($context['entity_id']);
$field_storage = FieldStorageConfig::loadByName($entity->getEntityTypeId(), $field_name);
$values = array(
'entity_type' => $entity->getEntityTypeId(),
'entity_id' => $entity->id(),
'field_name' => $field_name,
'comment_type' => $field_storage->getSetting('bundle'),
'entity_type' => $context['entity_type'],
'entity_id' => $context['entity_id'],
'field_name' => $context['field_name'],
'comment_type' => $context['comment_type'],
'pid' => NULL,
);
$comment = $this->entityManager->getStorage('comment')->create($values);
......
......@@ -204,6 +204,7 @@ public function viewElements(FieldItemListInterface $items) {
'entity_type' => $entity->getEntityTypeId(),
'entity_id' => $entity->id(),
'field_name' => $field_name,
'comment_type' => $this->getFieldSetting('comment_type'),
);
$placeholder = drupal_render_cache_generate_placeholder($callback, $context);
$output['comment_form'] = array(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment