class AjaxResponseAttachmentsProcessor implements AttachmentsResponseProcessorInterface (View source)

Processes attachments of AJAX responses.

Properties

protected AssetResolverInterface $assetResolver

The asset resolver service.

protected Config $config

A config object for the system performance configuration.

protected AssetCollectionRendererInterface $cssCollectionRenderer

The CSS asset collection renderer service.

protected AssetCollectionRendererInterface $jsCollectionRenderer

The JS asset collection renderer service.

protected RequestStack $requestStack

The request stack.

protected RendererInterface $renderer

The renderer.

protected ModuleHandlerInterface $moduleHandler

The module handler.

Methods

__construct(AssetResolverInterface $asset_resolver, ConfigFactoryInterface $config_factory, AssetCollectionRendererInterface $css_collection_renderer, AssetCollectionRendererInterface $js_collection_renderer, RequestStack $request_stack, RendererInterface $renderer, ModuleHandlerInterface $module_handler)

Constructs an AjaxResponseAttachmentsProcessor object.

processAttachments(AttachmentsInterface $response)

Processes the attachments of a response that has attachments.

array
buildAttachmentsCommands(AjaxResponse $response, Request $request)

Prepares the AJAX commands to attach assets.

Details

__construct(AssetResolverInterface $asset_resolver, ConfigFactoryInterface $config_factory, AssetCollectionRendererInterface $css_collection_renderer, AssetCollectionRendererInterface $js_collection_renderer, RequestStack $request_stack, RendererInterface $renderer, ModuleHandlerInterface $module_handler)

Constructs an AjaxResponseAttachmentsProcessor object.

Parameters

AssetResolverInterface $asset_resolver

An asset resolver.

ConfigFactoryInterface $config_factory

A config factory for retrieving required config objects.

AssetCollectionRendererInterface $css_collection_renderer

The CSS asset collection renderer.

AssetCollectionRendererInterface $js_collection_renderer

The JS asset collection renderer.

RequestStack $request_stack

The request stack.

RendererInterface $renderer

The renderer.

ModuleHandlerInterface $module_handler

The module handler.

AttachmentsInterface processAttachments(AttachmentsInterface $response)

Processes the attachments of a response that has attachments.

Libraries, JavaScript settings, feeds, HTML tags, HTML 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:

Parameters

AttachmentsInterface $response

The response to process.

Return Value

AttachmentsInterface

The processed response, with the attachments updated to reflect their final values.

Exceptions

InvalidArgumentException

protected array buildAttachmentsCommands(AjaxResponse $response, Request $request)

Prepares the AJAX commands to attach assets.

Parameters

AjaxResponse $response

The AJAX response to update.

Request $request

The request object that the AJAX is responding to.

Return Value

array

An array of commands ready to be returned as JSON.