class DfpHtmlResponseAttachmentsProcessor in Doubleclick for Publishers (DFP) 8
Processes attachments of HTML responses with Dfp slot attachments.
Hierarchy
- class \Drupal\Core\Render\HtmlResponseAttachmentsProcessor implements AttachmentsResponseProcessorInterface
- class \Drupal\dfp\DfpHtmlResponseAttachmentsProcessor
Expanded class hierarchy of DfpHtmlResponseAttachmentsProcessor
See also
\Drupal\Core\Render\HtmlResponseAttachmentsProcessor
\Drupal\dfp\View\TagViewBuilder
1 file declares its use of DfpHtmlResponseAttachmentsProcessor
1 string reference to 'DfpHtmlResponseAttachmentsProcessor'
1 service uses DfpHtmlResponseAttachmentsProcessor
File
- src/
DfpHtmlResponseAttachmentsProcessor.php, line 30 - Contains \Drupal\dfp\DfpResponseAttachmentsProcessor.
Namespace
Drupal\dfpView source
class DfpHtmlResponseAttachmentsProcessor extends HtmlResponseAttachmentsProcessor {
/**
* The HTML response attachments processor service.
*
* @var \Drupal\Core\Render\AttachmentsResponseProcessorInterface
*/
protected $htmlResponseAttachmentsProcessor;
/**
* The configuration factory.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
protected $configFactory;
/**
* The DFP token service.
*
* @var \Drupal\dfp\TokenInterface
*/
protected $token;
/**
* Constructs a DfpResponseAttachmentsProcessor object.
*
* @param \Drupal\Core\Render\AttachmentsResponseProcessorInterface $html_response_attachments_processor
* The HTML response attachments processor service.
* @param \Drupal\Core\Asset\AssetResolverInterface $asset_resolver
* An asset resolver.
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* A config factory for retrieving required config objects.
* @param \Drupal\Core\Asset\AssetCollectionRendererInterface $css_collection_renderer
* The CSS asset collection renderer.
* @param \Drupal\Core\Asset\AssetCollectionRendererInterface $js_collection_renderer
* The JS asset collection renderer.
* @param \Symfony\Component\HttpFoundation\RequestStack $request_stack
* The request stack.
* @param \Drupal\Core\Render\RendererInterface $renderer
* The renderer.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The module handler service.
*/
public function __construct(AttachmentsResponseProcessorInterface $html_response_attachments_processor, TokenInterface $token, AssetResolverInterface $asset_resolver, ConfigFactoryInterface $config_factory, AssetCollectionRendererInterface $css_collection_renderer, AssetCollectionRendererInterface $js_collection_renderer, RequestStack $request_stack, RendererInterface $renderer, ModuleHandlerInterface $module_handler) {
$this->htmlResponseAttachmentsProcessor = $html_response_attachments_processor;
$this->configFactory = $config_factory;
$this->token = $token;
parent::__construct($asset_resolver, $config_factory, $css_collection_renderer, $js_collection_renderer, $request_stack, $renderer, $module_handler);
}
/**
* {@inheritdoc}
*/
public function processAttachments(AttachmentsInterface $response) {
// @todo Convert to assertion once https://www.drupal.org/node/2408013 lands
if (!$response instanceof HtmlResponse) {
throw new \InvalidArgumentException('\\Drupal\\Core\\Render\\HtmlResponse instance expected.');
}
// First, render the actual placeholders. This may add attachments so this
// is a bit of unfortunate but necessary duplication.
// This is copied verbatim from
// \Drupal\Core\Render\HtmlResponseAttachmentsProcessor::processAttachments.
try {
$response = $this
->renderPlaceholders($response);
} catch (EnforcedResponseException $e) {
return $e
->getResponse();
}
// Extract DFP slots; HtmlResponseAttachmentsProcessor does not
// know (nor need to know) how to process those.
$attachments = $response
->getAttachments();
if (isset($attachments['dfp_slot'])) {
$attachments['html_head'][] = [
$this
->getHeadTop(),
'dfp-js-head-top',
];
/** @var \Drupal\dfp\View\TagView $tag */
foreach ($attachments['dfp_slot'] as $tag_view) {
$attachments['html_head'][] = [
[
// Use a fake #type to prevent
// HtmlResponseAttachmentsProcessor::processHead() adding one.
'#type' => 'dfp_script',
'#theme' => 'dfp_slot_definition_js',
'#tag' => $tag_view,
],
'dfp-slot-definition-' . $tag_view
->id(),
];
}
$attachments['html_head'][] = [
$this
->getHeadBottom(),
'dfp-js-head-bottom',
];
unset($attachments['dfp_slot']);
}
$response
->setAttachments($attachments);
// Call HtmlResponseAttachmentsProcessor to process all other attachments.
return $this->htmlResponseAttachmentsProcessor
->processAttachments($response);
}
/**
* Gets the javascript to add before the slot definitions.
*
* @return \Drupal\Component\Render\MarkupInterface
* The rendered HTML.
*/
protected function getHeadTop() {
return [
// Use a fake #type to prevent
// HtmlResponseAttachmentsProcessor::processHead() adding one.
'#type' => 'dfp_script',
'#theme' => 'dfp_js_head_top',
'#google_tag_services_url' => TagInterface::GOOGLE_TAG_SERVICES_URL,
];
}
/**
* Gets the javascript to add after the slot definitions.
*
* @return \Drupal\Component\Render\MarkupInterface
* The rendered HTML.
*/
protected function getHeadBottom() {
$global_settings = $this->configFactory
->get('dfp.settings');
$targeting = $global_settings
->get('targeting');
$this->moduleHandler
->alter('dfp_global_targeting', $targeting);
$targeting = TagView::formatTargeting($targeting, $this->token, $this->moduleHandler);
return [
// Use a fake #type to prevent
// HtmlResponseAttachmentsProcessor::processHead() adding one.
'#type' => 'dfp_script',
'#theme' => 'dfp_js_head_bottom',
'#async_rendering' => $global_settings
->get('async_rendering'),
'#single_request' => $global_settings
->get('single_request'),
'#collapse_empty_divs' => $global_settings
->get('collapse_empty_divs'),
'#disable_init_load' => $global_settings
->get('disable_init_load'),
'#targeting' => $targeting,
];
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DfpHtmlResponseAttachmentsProcessor:: |
protected | property | The configuration factory. | |
DfpHtmlResponseAttachmentsProcessor:: |
protected | property | The HTML response attachments processor service. | |
DfpHtmlResponseAttachmentsProcessor:: |
protected | property | The DFP token service. | |
DfpHtmlResponseAttachmentsProcessor:: |
protected | function | Gets the javascript to add after the slot definitions. | |
DfpHtmlResponseAttachmentsProcessor:: |
protected | function | Gets the javascript to add before the slot definitions. | |
DfpHtmlResponseAttachmentsProcessor:: |
public | function |
Processes the attachments of a response that has attachments. Overrides HtmlResponseAttachmentsProcessor:: |
|
DfpHtmlResponseAttachmentsProcessor:: |
public | function |
Constructs a DfpResponseAttachmentsProcessor object. Overrides HtmlResponseAttachmentsProcessor:: |
|
HtmlResponseAttachmentsProcessor:: |
protected | property | The asset resolver service. | |
HtmlResponseAttachmentsProcessor:: |
protected | property | A config object for the system performance configuration. | |
HtmlResponseAttachmentsProcessor:: |
protected | property | The CSS asset collection renderer service. | |
HtmlResponseAttachmentsProcessor:: |
protected | property | The JS asset collection renderer service. | |
HtmlResponseAttachmentsProcessor:: |
protected | property | The module handler service. | |
HtmlResponseAttachmentsProcessor:: |
protected | property | The renderer. | |
HtmlResponseAttachmentsProcessor:: |
protected | property | The request stack. | |
HtmlResponseAttachmentsProcessor:: |
public static | function | Formats an attribute string for an HTTP header. | |
HtmlResponseAttachmentsProcessor:: |
protected | function | Processes asset libraries into render arrays. | |
HtmlResponseAttachmentsProcessor:: |
protected | function | Transform a 'feed' attachment into an 'html_head_link' attachment. | |
HtmlResponseAttachmentsProcessor:: |
protected | function | Ensure proper key/data order and defaults for renderable head items. | |
HtmlResponseAttachmentsProcessor:: |
protected | function | Transform a html_head_link array into html_head and http_header arrays. | |
HtmlResponseAttachmentsProcessor:: |
protected | function | Renders HTML response attachment placeholders. | |
HtmlResponseAttachmentsProcessor:: |
protected | function | Renders placeholders (#attached['placeholders']). | |
HtmlResponseAttachmentsProcessor:: |
protected | function | Sets headers on a response object. |