Commit 5ca372cb authored by catch's avatar catch

Issue #2099133 by Wim Leers Comment form on same page as comments forces node...

Issue #2099133 by Wim Leers  Comment form on same page as comments forces node render caching to be per user.
parent e75ac464
......@@ -1731,20 +1731,3 @@ function comment_library_info() {
);
return $libraries;
}
/**
* #post_render_cache callback; replaces the placeholder with the comment form.
*
* @param array $context
* An array with the following keys:
* - entity_type: an entity type
* - entity_id: an entity ID
* - field_name: a comment field name
*
* @return array $element
* The updated $element.
*/
function comment_replace_form_placeholder(array $context) {
$entity = entity_load($context['entity_type'], $context['entity_id']);
return comment_add($entity, $context['field_name']);
}
......@@ -151,7 +151,7 @@ public function viewElements(FieldItemListInterface $items) {
else {
$output['comment_form'] = array(
'#type' => 'render_cache_placeholder',
'#callback' => 'comment_replace_form_placeholder',
'#callback' => '\Drupal\comment\Plugin\Field\FieldFormatter\CommentDefaultFormatter::renderForm',
'#context' => array(
'entity_type' => $entity->entityType(),
'entity_id' => $entity->id(),
......@@ -174,4 +174,21 @@ public function viewElements(FieldItemListInterface $items) {
return $elements;
}
/**
* #post_render_cache callback; replaces placeholder with comment form.
*
* @param array $context
* An array with the following keys:
* - entity_type: an entity type
* - entity_id: an entity ID
* - field_name: a comment field name
*
* @return array
* A renderable array containing the comment form.
*/
public static function renderForm(array $context) {
$entity = entity_load($context['entity_type'], $context['entity_id']);
return comment_add($entity, $context['field_name']);
}
}
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