You are here

function csp_update_8003 in Content-Security-Policy 8

Update configuration format.

File

./csp.install, line 103
Installation hooks for csp.module.

Code

function csp_update_8003() {
  $config = \Drupal::configFactory()
    ->getEditable('csp.settings');
  $enabledPolicy = 'report-only';
  $disabledPolicy = 'enforce';
  if ($config
    ->get('enforce')) {
    $enabledPolicy = 'enforce';
    $disabledPolicy = 'report-only';
  }
  $config
    ->set($enabledPolicy, [
    'enable' => TRUE,
    'directives' => [
      'script-src' => [
        'base' => 'self',
        'flags' => [
          'unsafe-inline',
        ],
      ],
      'style-src' => [
        'base' => 'self',
      ],
    ],
  ])
    ->set($disabledPolicy, [
    'enable' => FALSE,
  ])
    ->save();
}