From 5ca372cb4028404c9e7c9cd67eb25706f866b73d Mon Sep 17 00:00:00 2001 From: Nathaniel Catchpole Date: Tue, 26 Nov 2013 10:07:46 +0000 Subject: [PATCH] Issue #2099133 by Wim Leers Comment form on same page as comments forces node render caching to be per user. --- core/modules/comment/comment.module | 17 ----------------- .../CommentDefaultFormatter.php | 19 ++++++++++++++++++- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/core/modules/comment/comment.module b/core/modules/comment/comment.module index 6189c720529..6fcbc2be43a 100644 --- a/core/modules/comment/comment.module +++ b/core/modules/comment/comment.module @@ -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']); -} diff --git a/core/modules/comment/lib/Drupal/comment/Plugin/Field/FieldFormatter/CommentDefaultFormatter.php b/core/modules/comment/lib/Drupal/comment/Plugin/Field/FieldFormatter/CommentDefaultFormatter.php index 4ae0c45bdec..5c1d9ea8b6d 100644 --- a/core/modules/comment/lib/Drupal/comment/Plugin/Field/FieldFormatter/CommentDefaultFormatter.php +++ b/core/modules/comment/lib/Drupal/comment/Plugin/Field/FieldFormatter/CommentDefaultFormatter.php @@ -151,7 +151,7 @@ class CommentDefaultFormatter extends FormatterBase implements ContainerFactoryP 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 @@ class CommentDefaultFormatter extends FormatterBase implements ContainerFactoryP 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']); + } + }