Drupal 8  8.0.2
AjaxResponseAttachmentsProcessor Class Reference
Inheritance diagram for AjaxResponseAttachmentsProcessor:

Public Member Functions

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

Protected Member Functions

 buildAttachmentsCommands (AjaxResponse $response, Request $request)
 

Protected Attributes

 $assetResolver
 
 $config
 
 $cssCollectionRenderer
 
 $jsCollectionRenderer
 
 $requestStack
 
 $renderer
 
 $moduleHandler
 

Detailed Description

Processes attachments of AJAX responses.

See Also

Constructor & Destructor Documentation

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

Constructs a AjaxResponseAttachmentsProcessor object.

Parameters
\Drupal\Core\Asset\AssetResolverInterface$asset_resolverAn asset resolver.
\Drupal\Core\Config\ConfigFactoryInterface$config_factoryA config factory for retrieving required config objects.
\Drupal\Core\Asset\AssetCollectionRendererInterface$css_collection_rendererThe CSS asset collection renderer.
\Drupal\Core\Asset\AssetCollectionRendererInterface$js_collection_rendererThe JS asset collection renderer.
\Symfony\Component\HttpFoundation\RequestStack$request_stackThe request stack.
\Drupal\Core\Render\RendererInterface$rendererThe renderer.
\Drupal\Core\Extension\ModuleHandlerInterface$module_handlerThe module handler.

References Drupal\config(), ConfigFactoryInterface\get(), Drupal\moduleHandler(), and Drupal\requestStack().

Here is the call graph for this function:

Member Function Documentation

buildAttachmentsCommands ( AjaxResponse  $response,
Request  $request 
)
protected

Prepares the AJAX commands to attach assets.

Parameters
\Drupal\Core\Ajax\AjaxResponse$responseThe AJAX response to update.
\Symfony\Component\HttpFoundation\Request$requestThe request object that the AJAX is responding to.
Returns
array An array of commands ready to be returned as JSON.

References AjaxResponse\addCommand(), Drupal\config(), AttachmentsInterface\getAttachments(), AjaxResponse\getCommands(), Drupal\moduleHandler(), PrependCommand\render(), AddCssCommand\render(), and AttachmentsInterface\setAttachments().

Referenced by AjaxResponseAttachmentsProcessor\processAttachments().

Here is the call graph for this function:

Here is the caller graph for this function:

processAttachments ( AttachmentsInterface  $response)

{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:

$build['#attached']['library'][] = [
'library' => ['core/jquery']
];
$build['#attached']['http_header'][] = [
['Content-Type', 'application/rss+xml; charset=utf-8'],
];
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)
Parameters
\Drupal\Core\Render\AttachmentsInterface$responseThe response to process.
Returns
The processed response, with the attachments updated to reflect their final values.
Exceptions
\InvalidArgumentExceptionThrown when the $response parameter is not the type of response object the processor expects.
}

Implements AttachmentsResponseProcessorInterface.

References AjaxResponseAttachmentsProcessor\buildAttachmentsCommands(), and Drupal\requestStack().

Here is the call graph for this function:


The documentation for this class was generated from the following file: