BubbleableMetadata::merge

public BubbleableMetadata::merge(CacheableMetadata $other)

Merges the values of another bubbleable metadata object with this one.

Parameters

\Drupal\Core\Cache\CacheableMetadata $other: The other bubbleable metadata object.

Return value

static A new bubbleable metadata object, with the merged data.

Overrides CacheableMetadata::merge

File

core/lib/Drupal/Core/Render/BubbleableMetadata.php, line 26

Class

BubbleableMetadata
Value object used for bubbleable rendering metadata.

Namespace

Drupal\Core\Render

Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
public function merge(CacheableMetadata $other) {
  $result = parent::merge($other);
 
  // This is called many times per request, so avoid merging unless absolutely
  // necessary.
  if ($other instanceof BubbleableMetadata) {
    if (empty($this->attachments)) {
      $result->attachments = $other->attachments;
    }
    elseif (empty($other->attachments)) {
      $result->attachments = $this->attachments;
    }
    else {
      $result->attachments = static::mergeAttachments($this->attachments, $other->attachments);
    }
  }
 
  return $result;
}
doc_Drupal
2025-01-10 15:47:30
Comments
Leave a Comment

Please login to continue.