You are here

public function ReportUri::getForm in Content-Security-Policy 8

Get the form fields for configuring this reporting handler.

Parameters

array $form: The plugin parent form element.

Return value

array A Form array.

Overrides ReportingHandlerBase::getForm

File

src/Plugin/CspReportingHandler/ReportUri.php, line 28

Class

ReportUri
CSP Reporting Plugin for ReportURI service.

Namespace

Drupal\csp\Plugin\CspReportingHandler

Code

public function getForm(array $form) {
  $form['subdomain'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Subdomain'),
    '#description' => $this
      ->t('Your <a href=":url">Report-URI.com subdomain</a>.', [
      ':url' => 'https://report-uri.com/account/setup/',
    ]),
    '#default_value' => isset($this->configuration['subdomain']) ? $this->configuration['subdomain'] : '',
    '#states' => [
      'required' => [
        ':input[name="' . $this->configuration['type'] . '[enable]"]' => [
          'checked' => TRUE,
        ],
        ':input[name="' . $this->configuration['type'] . '[reporting][handler]"]' => [
          'value' => $this->pluginId,
        ],
      ],
    ],
  ];
  if ($this->configuration['type'] == 'report-only') {
    $form['wizard'] = [
      '#type' => 'checkbox',
      '#title' => $this
        ->t('Enable Wizard'),
      '#description' => $this
        ->t('Send reports to the <a href=":url">CSP Wizard</a> reporting address.', [
        ':url' => 'https://report-uri.com/account/wizard/csp/',
      ]),
      '#default_value' => !empty($this->configuration['wizard']),
    ];
  }
  unset($form['#description']);
  return $form;
}