diff --git a/core/lib/Drupal/Core/Render/AttachmentsInterface.php b/core/lib/Drupal/Core/Render/AttachmentsInterface.php index bd0e5a853b7099e07831960995eb2c8168818a68..b32d6876e7292503fdeb9dc64364621fb5653e11 100644 --- a/core/lib/Drupal/Core/Render/AttachmentsInterface.php +++ b/core/lib/Drupal/Core/Render/AttachmentsInterface.php @@ -3,7 +3,31 @@ namespace Drupal\Core\Render; /** - * Defines an interface for responses that can expose #attached metadata. + * 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 @@ -14,15 +38,15 @@ interface AttachmentsInterface { /** - * Gets attachments. + * Gets this object's attached collection. * * @return array - * The attachments. + * The attachments array. */ public function getAttachments(); /** - * Adds attachments. + * Merges an array of attached data into this object's collection. * * @param array $attachments * The attachments to add. @@ -32,7 +56,7 @@ public function getAttachments(); public function addAttachments(array $attachments); /** - * Sets attachments. + * Replaces this object's attached data with the provided array. * * @param array $attachments * The attachments to set. diff --git a/core/lib/Drupal/Core/Render/AttachmentsResponseProcessorInterface.php b/core/lib/Drupal/Core/Render/AttachmentsResponseProcessorInterface.php index 31ba55cc9f4756db9c8739788d6cdf24f58ec057..494377e255aa2ff48213d9fc45641062761c0e7a 100644 --- a/core/lib/Drupal/Core/Render/AttachmentsResponseProcessorInterface.php +++ b/core/lib/Drupal/Core/Render/AttachmentsResponseProcessorInterface.php @@ -7,6 +7,7 @@ * * @see \Drupal\Core\Ajax\AjaxResponse * @see \Drupal\Core\Ajax\AjaxResponseAttachmentsProcessor + * @see \Drupal\Core\Render\AttachmentsInterface * @see \Drupal\Core\Render\HtmlResponse * @see \Drupal\Core\Render\HtmlResponseAttachmentsProcessor */ @@ -15,29 +16,6 @@ interface AttachmentsResponseProcessorInterface { /** * Processes the attachments of a response that has attachments. * - * 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'][] = [ - * 'library' => ['core/jquery'] - * ]; - * $build['#attached']['http_header'] = [ - * ['Content-Type', 'application/rss+xml; charset=utf-8'], - * ]; - * @endcode - * - * The available keys are: - * - 'library' (asset libraries) - * - 'drupalSettings' (JavaScript settings) - * - 'feed' (RSS feeds) - * - 'html_head' (tags in HTML <head>) - * - 'html_head_link' (<link> tags in HTML <head>) - * - 'http_header' (HTTP headers and status code) - * * Placeholders need to be rendered first in order to have all attachments * available for processing. For an example, see * \Drupal\Core\Render\HtmlResponseAttachmentsProcessor::renderPlaceholders() @@ -52,6 +30,8 @@ interface AttachmentsResponseProcessorInterface { * @throws \InvalidArgumentException * Thrown when the $response parameter is not the type of response object * the processor expects. + * + * @see \Drupal\Core\Render\AttachmentsInterface */ public function processAttachments(AttachmentsInterface $response);