AttachmentsResponseProcessorInterface.php 1.76 KB
Newer Older
1 2 3 4 5 6 7
<?php

namespace Drupal\Core\Render;

/**
 * Defines an interface for processing attachments of responses that have them.
 *
8 9
 * @see \Drupal\Core\Ajax\AjaxResponse
 * @see \Drupal\Core\Ajax\AjaxResponseAttachmentsProcessor
10 11 12 13 14 15 16 17
 * @see \Drupal\Core\Render\HtmlResponse
 * @see \Drupal\Core\Render\HtmlResponseAttachmentsProcessor
 */
interface AttachmentsResponseProcessorInterface {

  /**
   * Processes the attachments of a response that has attachments.
   *
18 19 20 21 22 23 24 25 26 27
   * 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']
   * ];
28
   * $build['#attached']['http_header'] = [
29 30 31 32 33 34 35 36 37 38 39 40
   *   ['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)
   *
41
   * @param \Drupal\Core\Render\AttachmentsInterface $response
42
   *   The response to process.
43 44
   *
   * @return \Drupal\Core\Render\AttachmentsInterface
45 46
   *   The processed response, with the attachments updated to reflect their
   *   final values.
47 48
   *
   * @throws \InvalidArgumentException
49 50
   *   Thrown when the $response parameter is not the type of response object
   *   the processor expects.
51 52 53 54
   */
  public function processAttachments(AttachmentsInterface $response);

}