Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. BubbleableMetadata.php

function BubbleableMetadata::merge

Creates a new bubbleable metadata object by merging this one with another.

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

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;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal