diff --git a/core/core.services.yml b/core/core.services.yml index 49f6547681576c87647e5051fc83008e7f077d33..e39f6352c88a2e5e5b818c781f6bed012e074833 100644 --- a/core/core.services.yml +++ b/core/core.services.yml @@ -1204,7 +1204,7 @@ services: arguments: ['@resolver_manager.entity'] ajax_response.subscriber: class: Drupal\Core\EventSubscriber\AjaxResponseSubscriber - arguments: ['@ajax_response.attachments_processor'] + autowire: true form_ajax_subscriber: class: Drupal\Core\Form\EventSubscriber\FormAjaxSubscriber arguments: ['@form_ajax_response_builder', '@string_translation', '@messenger'] diff --git a/core/lib/Drupal/Core/EventSubscriber/AjaxResponseSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/AjaxResponseSubscriber.php index 9869f72882694c8844bccaabe221c82df963b417..d4b5bccd87e982862b6b83b46a836386701f62e3 100644 --- a/core/lib/Drupal/Core/EventSubscriber/AjaxResponseSubscriber.php +++ b/core/lib/Drupal/Core/EventSubscriber/AjaxResponseSubscriber.php @@ -4,7 +4,8 @@ use Drupal\Component\Utility\Html; use Drupal\Core\Ajax\AjaxResponse; -use Drupal\Core\Render\AttachmentsResponseProcessorInterface; +use Drupal\Core\DependencyInjection\DeprecatedServicePropertyTrait; +use Symfony\Component\DependencyInjection\Attribute\AutowireServiceClosure; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\HttpKernel\Event\ResponseEvent; use Symfony\Component\HttpKernel\Event\RequestEvent; @@ -15,22 +16,25 @@ */ class AjaxResponseSubscriber implements EventSubscriberInterface { + use DeprecatedServicePropertyTrait; + /** - * The AJAX response attachments processor service. - * - * @var \Drupal\Core\Render\AttachmentsResponseProcessorInterface + * {@inheritdoc} */ - protected $ajaxResponseAttachmentsProcessor; + protected array $deprecatedProperties = [ + 'ajaxResponseAttachmentsProcessor' => 'ajax_response.attachments_processor', + ]; /** * Constructs an AjaxResponseSubscriber object. * - * @param \Drupal\Core\Render\AttachmentsResponseProcessorInterface $ajax_response_attachments_processor - * The AJAX response attachments processor service. + * @param \Closure $processorClosure + * The AJAX response attachments processor service, wrapped in a closure. */ - public function __construct(AttachmentsResponseProcessorInterface $ajax_response_attachments_processor) { - $this->ajaxResponseAttachmentsProcessor = $ajax_response_attachments_processor; - } + public function __construct( + #[AutowireServiceClosure('ajax_response.attachments_processor')] + protected \Closure $processorClosure + ) {} /** * Request parameter to indicate that a request is a Drupal Ajax request. @@ -59,7 +63,7 @@ public function onRequest(RequestEvent $event) { public function onResponse(ResponseEvent $event) { $response = $event->getResponse(); if ($response instanceof AjaxResponse) { - $this->ajaxResponseAttachmentsProcessor->processAttachments($response); + ($this->processorClosure)()->processAttachments($response); // IE 9 does not support XHR 2 (http://caniuse.com/#feat=xhr2), so // for that browser, jquery.form submits requests containing a file upload diff --git a/core/tests/Drupal/KernelTests/Core/Ajax/CommandsTest.php b/core/tests/Drupal/KernelTests/Core/Ajax/CommandsTest.php index b4480f160bb68547d6d1cb8fe5d8c275b726cb7b..7dda4f4bc2650de98f50aefee20aff61235aecc1 100644 --- a/core/tests/Drupal/KernelTests/Core/Ajax/CommandsTest.php +++ b/core/tests/Drupal/KernelTests/Core/Ajax/CommandsTest.php @@ -39,7 +39,7 @@ public function testAttachedSettings() { ]); $ajax_response_attachments_processor = \Drupal::service('ajax_response.attachments_processor'); - $subscriber = new AjaxResponseSubscriber($ajax_response_attachments_processor); + $subscriber = new AjaxResponseSubscriber(fn() => $ajax_response_attachments_processor); $event = new ResponseEvent( \Drupal::service('http_kernel'), new Request(), diff --git a/core/tests/Drupal/Tests/Core/Ajax/AjaxResponseTest.php b/core/tests/Drupal/Tests/Core/Ajax/AjaxResponseTest.php index 0033fd3b41ef4b5631c6172f6f8316b71f2f17d2..ac17d076509101a1551f3f2d294bf4466cdb29f3 100644 --- a/core/tests/Drupal/Tests/Core/Ajax/AjaxResponseTest.php +++ b/core/tests/Drupal/Tests/Core/Ajax/AjaxResponseTest.php @@ -86,7 +86,7 @@ public function testPrepareResponseForIeFormRequestsWithFileUpload() { $response->headers->set('Content-Type', 'application/json; charset=utf-8'); $ajax_response_attachments_processor = $this->createMock('\Drupal\Core\Render\AttachmentsResponseProcessorInterface'); - $subscriber = new AjaxResponseSubscriber($ajax_response_attachments_processor); + $subscriber = new AjaxResponseSubscriber(fn() => $ajax_response_attachments_processor); $event = new ResponseEvent( $this->createMock('\Symfony\Component\HttpKernel\HttpKernelInterface'), $request,