class ReportUri in Content-Security-Policy 8
Same name in this branch
- 8 src/Controller/ReportUri.php \Drupal\csp\Controller\ReportUri
- 8 src/Plugin/CspReportingHandler/ReportUri.php \Drupal\csp\Plugin\CspReportingHandler\ReportUri
CSP Reporting Plugin for ReportURI service.
Plugin annotation
@CspReportingHandler(
id = "report-uri-com",
label = "Report URI",
description = @Translation("Reports will be sent to a ReportURI.com account."),
)
Hierarchy
- class \Drupal\csp\Plugin\ReportingHandlerBase implements ReportingHandlerInterface
- class \Drupal\csp\Plugin\CspReportingHandler\ReportUri uses StringTranslationTrait
Expanded class hierarchy of ReportUri
See also
report-uri.com
File
- src/
Plugin/ CspReportingHandler/ ReportUri.php, line 21
Namespace
Drupal\csp\Plugin\CspReportingHandlerView source
class ReportUri extends ReportingHandlerBase {
use StringTranslationTrait;
/**
* {@inheritdoc}
*/
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;
}
/**
* {@inheritdoc}
*/
public function validateForm(array &$form, FormStateInterface $form_state) {
$subdomain = $form_state
->getValue($form['subdomain']['#parents']);
// Custom domains must be 4-30 characters, but generated domains are 32.
if (!preg_match('/^[a-z\\d]{4,32}$/i', $subdomain)) {
$form_state
->setError($form['subdomain'], 'Must be 4-30 alphanumeric characters.');
}
}
/**
* {@inheritdoc}
*/
public function alterPolicy(Csp $policy) {
$type = 'enforce';
if ($this->configuration['type'] == 'report-only') {
$type = empty($this->configuration['wizard']) ? 'reportOnly' : 'wizard';
}
$policy
->setDirective('report-uri', 'https://' . $this->configuration['subdomain'] . '.report-uri.com/r/d/csp/' . $type);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ReportingHandlerBase:: |
protected | property | The Plugin Configuration. | |
ReportingHandlerBase:: |
protected | property | The Plugin Definition. | |
ReportingHandlerBase:: |
protected | property | The Plugin ID. | |
ReportingHandlerBase:: |
public | function | Reporting Handler plugin constructor. | |
ReportUri:: |
public | function |
Alter the provided policy according to the plugin settings. Overrides ReportingHandlerBase:: |
|
ReportUri:: |
public | function |
Get the form fields for configuring this reporting handler. Overrides ReportingHandlerBase:: |
|
ReportUri:: |
public | function |
Validate the form fields of this report handler. Overrides ReportingHandlerBase:: |
|
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |