AttachmentsResponseProcessorInterface.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. namespace Drupal\Core\Render;
  3. /**
  4. * Defines an interface for processing attachments of responses that have them.
  5. *
  6. * @see \Drupal\Core\Ajax\AjaxResponse
  7. * @see \Drupal\Core\Ajax\AjaxResponseAttachmentsProcessor
  8. * @see \Drupal\Core\Render\HtmlResponse
  9. * @see \Drupal\Core\Render\HtmlResponseAttachmentsProcessor
  10. */
  11. interface AttachmentsResponseProcessorInterface {
  12. /**
  13. * Processes the attachments of a response that has attachments.
  14. *
  15. * Libraries, JavaScript settings, feeds, HTML <head> tags, HTML <head> links,
  16. * HTTP headers, and the HTTP status code are attached to render arrays using
  17. * the #attached property. The #attached property is an associative array,
  18. * where the keys are the attachment types and the values are the attached
  19. * data. For example:
  20. *
  21. * @code
  22. * $build['#attached']['library'][] = [
  23. * 'library' => ['core/jquery']
  24. * ];
  25. * $build['#attached']['http_header'] = [
  26. * ['Content-Type', 'application/rss+xml; charset=utf-8'],
  27. * ];
  28. * @endcode
  29. *
  30. * The available keys are:
  31. * - 'library' (asset libraries)
  32. * - 'drupalSettings' (JavaScript settings)
  33. * - 'feed' (RSS feeds)
  34. * - 'html_head' (tags in HTML <head>)
  35. * - 'html_head_link' (<link> tags in HTML <head>)
  36. * - 'http_header' (HTTP headers and status code)
  37. *
  38. * @param \Drupal\Core\Render\AttachmentsInterface $response
  39. * The response to process.
  40. *
  41. * @return \Drupal\Core\Render\AttachmentsInterface
  42. * The processed response, with the attachments updated to reflect their
  43. * final values.
  44. *
  45. * @throws \InvalidArgumentException
  46. * Thrown when the $response parameter is not the type of response object
  47. * the processor expects.
  48. */
  49. public function processAttachments(AttachmentsInterface $response);
  50. }