class Uri in Content-Security-Policy 8
CSP Reporting Plugin for a URI endpoint.
Plugin annotation
@CspReportingHandler(
id = "uri",
label = "URI",
description = @Translation("Reports will be sent to a URI."),
)
Hierarchy
- class \Drupal\csp\Plugin\ReportingHandlerBase implements ReportingHandlerInterface
- class \Drupal\csp\Plugin\CspReportingHandler\Uri uses StringTranslationTrait
Expanded class hierarchy of Uri
File
- src/
Plugin/ CspReportingHandler/ Uri.php, line 20
Namespace
Drupal\csp\Plugin\CspReportingHandlerView source
class Uri extends ReportingHandlerBase {
use StringTranslationTrait;
/**
* {@inheritdoc}
*/
public function getForm(array $form) {
$form['uri'] = [
'#type' => 'textfield',
'#title' => $this
->t('URI'),
'#description' => $this
->t('The URI to send reports to.'),
'#default_value' => isset($this->configuration['uri']) ? $this->configuration['uri'] : '',
'#states' => [
'required' => [
':input[name="' . $this->configuration['type'] . '[enable]"]' => [
'checked' => TRUE,
],
':input[name="' . $this->configuration['type'] . '[reporting][handler]"]' => [
'value' => $this->pluginId,
],
],
],
];
unset($form['#description']);
return $form;
}
/**
* {@inheritdoc}
*/
public function validateForm(array &$form, FormStateInterface $form_state) {
$uri = $form_state
->getValue($form['uri']['#parents']);
if (!(UrlHelper::isValid($uri, TRUE) && preg_match('/^https?:/', $uri))) {
$form_state
->setError($form['uri'], 'Must be a valid http or https URL.');
}
}
/**
* {@inheritdoc}
*/
public function alterPolicy(Csp $policy) {
$policy
->setDirective('report-uri', $this->configuration['uri']);
}
}
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. | |
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. | |
Uri:: |
public | function |
Alter the provided policy according to the plugin settings. Overrides ReportingHandlerBase:: |
|
Uri:: |
public | function |
Get the form fields for configuring this reporting handler. Overrides ReportingHandlerBase:: |
|
Uri:: |
public | function |
Validate the form fields of this report handler. Overrides ReportingHandlerBase:: |