public function CspSubscriber::onCspPolicyAlter in Blazy 8.2
Alter CSP policy to allow data img-src.
Parameters
\Drupal\csp\Event\PolicyAlterEvent $alterEvent: The Policy Alter event.
File
- src/
EventSubscriber/ CspSubscriber.php, line 51
Class
- CspSubscriber
- Alter CSP policy for Blazy.
Namespace
Drupal\blazy\EventSubscriberCode
public function onCspPolicyAlter(PolicyAlterEvent $alterEvent) : void {
$policy = $alterEvent
->getPolicy();
$response = $alterEvent
->getResponse();
if ($response instanceof AttachmentsInterface) {
$attachments = $response
->getAttachments();
$libraries = isset($attachments['library']) ? $this->libraryDependencyResolver
->getLibrariesWithDependencies($attachments['library']) : [];
if (in_array('blazy/load', $libraries)) {
$policy
->fallbackAwareAppendIfEnabled('img-src', [
'data:',
]);
}
}
}