core/includes/common.inc | 6 ++-- .../modules/comment/src/CommentPostRenderCache.php | 35 ++++++++++------------ 2 files changed, 17 insertions(+), 24 deletions(-) diff --git a/core/includes/common.inc b/core/includes/common.inc index edcbe2c..a6b02d0 100644 --- a/core/includes/common.inc +++ b/core/includes/common.inc @@ -1077,10 +1077,8 @@ function drupal_pre_render_links($element) { // cannot be mistakenly rendered twice). $child['#printed'] = TRUE; } - // Merge attachments. - if (isset($child['#attached'])) { - $element['#attached'] = drupal_merge_attached($element['#attached'], $child['#attached']); - } + // Merge bubbleable metadata. + $element = \Drupal::service('renderer')->mergeBubbleableMetadata($element, $child); } return $element; } diff --git a/core/modules/comment/src/CommentPostRenderCache.php b/core/modules/comment/src/CommentPostRenderCache.php index 960c06f..5262995 100644 --- a/core/modules/comment/src/CommentPostRenderCache.php +++ b/core/modules/comment/src/CommentPostRenderCache.php @@ -274,26 +274,21 @@ public function attachNewCommentsLinkMetadata(array $element, array $context) { $query = $page_number ? array('page' => $page_number) : NULL; // Attach metadata. - $element['#attached']['js'][] = array( - 'type' => 'setting', - 'data' => array( - 'comment' => array( - 'newCommentsLinks' => array( - $context['entity_type'] => array( - $context['field_name'] => array( - $context['entity_id'] => array( - 'new_comment_count' => (int) $new, - 'first_new_comment_link' => $entity->url('canonical', [ - 'query' => $query, - 'fragment' => 'new', - ]), - ), - ), - ), - ), - ), - ), - ); + $parents = [ + 'comment', + 'newCommentsLinks', + $context['entity_type'], + $context['field_name'], + $context['entity_id'] + ]; + $value = [ + 'new_comment_count' => (int) $new, + 'first_new_comment_link' => $entity->url('canonical', [ + 'query' => $query, + 'fragment' => 'new', + ]), + ]; + NestedArray::setValue($element['#attached']['drupalSettings'], $parents, $value); return $element; }