You are here

public function Uri::validateForm in Content-Security-Policy 8

Validate the form fields of this report handler.

Parameters

array $form: The form fields for this plugin.

\Drupal\Core\Form\FormStateInterface $form_state: The submitted form state.

Overrides ReportingHandlerBase::validateForm

File

src/Plugin/CspReportingHandler/Uri.php, line 50

Class

Uri
CSP Reporting Plugin for a URI endpoint.

Namespace

Drupal\csp\Plugin\CspReportingHandler

Code

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.');
  }
}