private static function CspSubscriber::fallbackAwareAppendIfEnabled in Raven: Sentry Integration 3.x
Same name and namespace in other branches
- 8.2 src/EventSubscriber/CspSubscriber.php \Drupal\raven\EventSubscriber\CspSubscriber::fallbackAwareAppendIfEnabled()
Append to a directive if it or a fallback directive is enabled.
If the specified directive is not enabled but one of its fallback directives is, it will be initialized with the same value as the fallback before appending the new value.
If none of the specified directive's fallbacks are enabled, the directive will not be enabled.
Parameters
\Drupal\csp\Csp $policy: The CSP directive to alter.
string $directive: The directive name.
array|string $value: The directive value.
1 call to CspSubscriber::fallbackAwareAppendIfEnabled()
- CspSubscriber::onCspPolicyAlter in src/
EventSubscriber/ CspSubscriber.php - Alter CSP policy to allow Sentry to send JS errors.
File
- src/
EventSubscriber/ CspSubscriber.php, line 90
Class
- CspSubscriber
- Subscriber for CSP events.
Namespace
Drupal\raven\EventSubscriberCode
private static function fallbackAwareAppendIfEnabled(Csp $policy, $directive, $value) {
if ($policy
->hasDirective($directive)) {
$policy
->appendDirective($directive, $value);
return;
}
// Duplicate the closest fallback directive with a value.
foreach (Csp::getDirectiveFallbackList($directive) as $fallback) {
if ($policy
->hasDirective($fallback)) {
$policy
->setDirective($directive, $policy
->getDirective($fallback));
$policy
->appendDirective($directive, $value);
return;
}
}
}