.../src/Plugin/Field/FieldFormatter/CommentDefaultFormatter.php | 4 ++-- .../field/src/Tests/EntityReference/EntityReferenceFormatterTest.php | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/core/modules/comment/src/Plugin/Field/FieldFormatter/CommentDefaultFormatter.php b/core/modules/comment/src/Plugin/Field/FieldFormatter/CommentDefaultFormatter.php index 251dce0..be747b4 100644 --- a/core/modules/comment/src/Plugin/Field/FieldFormatter/CommentDefaultFormatter.php +++ b/core/modules/comment/src/Plugin/Field/FieldFormatter/CommentDefaultFormatter.php @@ -157,7 +157,7 @@ public function viewElements(FieldItemListInterface $items) { // Unpublished comments are not included in // $entity->get($field_name)->comment_count, but unpublished comments // should display if the user is an administrator. - $output['comments']['#cache']['contexts'][] = 'user.roles'; + $elements['#cache']['contexts'][] = 'user.roles'; if ($this->currentUser->hasPermission('access comments') || $this->currentUser->hasPermission('administer comments')) { // This is a listing of Comment entities, so associate its list cache // tag for correct invalidation. @@ -183,7 +183,7 @@ public function viewElements(FieldItemListInterface $items) { // display below the entity. Do not show the form for the print view mode. if ($status == CommentItemInterface::OPEN && $comment_settings['form_location'] == CommentItemInterface::FORM_BELOW && $this->viewMode != 'print') { // Only show the add comment form if the user has permission. - $output['comments']['#cache']['contexts'][] = 'user.roles'; + $elements['#cache']['contexts'][] = 'user.roles'; if ($this->currentUser->hasPermission('post comments')) { // All users in the "anonymous" role can use the same form: it is fine // for this form to be stored in the render cache. diff --git a/core/modules/field/src/Tests/EntityReference/EntityReferenceFormatterTest.php b/core/modules/field/src/Tests/EntityReference/EntityReferenceFormatterTest.php index d940188..9120f4a 100644 --- a/core/modules/field/src/Tests/EntityReference/EntityReferenceFormatterTest.php +++ b/core/modules/field/src/Tests/EntityReference/EntityReferenceFormatterTest.php @@ -230,6 +230,7 @@ public function testLabelFormatter() { $expected_item_2 = array( '#markup' => $this->unsavedReferencedEntity->label(), '#cache' => array( + 'contexts' => [], 'tags' => $this->unsavedReferencedEntity->getCacheTags(), ), );