summaryrefslogtreecommitdiffstatshomepage
path: root/core/lib/Drupal/Core/Render/AttachmentsInterface.php
blob: b32d6876e7292503fdeb9dc64364621fb5653e11 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php

namespace Drupal\Core\Render;

/**
 * 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:
 *
 * @code
 *  $build['#attached']['library'][] = 'core/jquery';
 *  $build['#attached']['http_header'] = [
 *    ['Content-Type', 'application/rss+xml; charset=utf-8'],
 *  ];
 * @endcode
 *
 * 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.
 *
 * @see \Drupal\Core\Render\AttachmentsTrait
 */
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);

}