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

Breadcrumb

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

interface AttachmentsInterface

The attached metadata collection for a renderable element.

Libraries, JavaScript settings, feeds, HTML <head> tags, HTML <head> links, HTTP headers, and the HTTP status code are attached to render arrays using the #attached property. The #attached property is an associative array, where the keys are the attachment types and the values are the attached data. For example:

$build['#attached']['library'][] = 'core/jquery';
$build['#attached']['http_header'] = [
    [
        'Content-Type',
        'application/rss+xml; charset=utf-8',
    ],
];

The keys used by core are:

  • drupalSettings: (optional) JavaScript settings.
  • feed: (optional) RSS feeds.
  • html_head: (optional) Tags used in HTML <head>.
  • html_head_link: (optional) The <link> tags in HTML <head>.
  • http_header: (optional) HTTP headers and status code.
  • html_response_attachment_placeholders: (optional) Placeholders used in a response attachment
  • library: (optional) Asset libraries.
  • placeholders: (optional) Any placeholders.

@todo If in Drupal 9, we remove attachments other than assets (libraries + drupalSettings), then we can look into unifying this with \Drupal\Core\Asset\AttachedAssetsInterface.

Hierarchy

  • interface \Drupal\Core\Render\AttachmentsInterface

Expanded class hierarchy of AttachmentsInterface

All classes that implement AttachmentsInterface

See also

\Drupal\Core\Render\AttachmentsTrait

6 files declare their use of AttachmentsInterface
AjaxResponse.php in core/lib/Drupal/Core/Ajax/AjaxResponse.php
AjaxResponseAttachmentsProcessor.php in core/lib/Drupal/Core/Ajax/AjaxResponseAttachmentsProcessor.php
BigPipeResponseAttachmentsProcessor.php in core/modules/big_pipe/src/Render/BigPipeResponseAttachmentsProcessor.php
EarlyRenderingControllerWrapperSubscriber.php in core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php
Token.php in core/lib/Drupal/Core/Utility/Token.php

... See full list

File

core/lib/Drupal/Core/Render/AttachmentsInterface.php, line 38

Namespace

Drupal\Core\Render
View source
interface AttachmentsInterface {
    
    /**
     * Gets this object's attached collection.
     *
     * @return array
     *   The attachments array.
     */
    public function getAttachments();
    
    /**
     * Merges an array of attached data into this object's collection.
     *
     * @param array $attachments
     *   The attachments to add.
     *
     * @return $this
     */
    public function addAttachments(array $attachments);
    
    /**
     * Replaces this object's attached data with the provided array.
     *
     * @param array $attachments
     *   The attachments to set.
     *
     * @return $this
     */
    public function setAttachments(array $attachments);

}

Members

Title Sort descending Modifiers Object type Summary
AttachmentsInterface::addAttachments public function Merges an array of attached data into this object&#039;s collection.
AttachmentsInterface::getAttachments public function Gets this object&#039;s attached collection.
AttachmentsInterface::setAttachments public function Replaces this object&#039;s attached data with the provided array.
RSS feed
Powered by Drupal