You are here

public function RemoveHttpHeadersSettings::validateForm in Remove HTTP headers 8

We cannot add a return typehint or add a return type. Because of the interface / PHPCS rule "Drupal.Commenting.FunctionComment.VoidReturn".

@phpstan-ignore-next-line

Overrides FormBase::validateForm

File

src/Form/RemoveHttpHeadersSettings.php, line 94

Class

RemoveHttpHeadersSettings
Form for the module settings.

Namespace

Drupal\remove_http_headers\Form

Code

public function validateForm(array &$form, FormStateInterface $form_state) {
  $headersToRemove = $this
    ->convertHeadersToRemoveValueToArray($form_state
    ->getValue('headers_to_remove'));
  foreach ($headersToRemove as $headerToRemove) {

    // Set error if any HTTP header contains whitespace.
    preg_match('/^[^\\s]+$/', $headerToRemove, $matches);
    if (count($matches) !== 1) {
      $form_state
        ->setErrorByName('headers_to_remove', $this
        ->t('The format of the "HTTP headers" field is not valid.</br>Make sure every HTTP header is on a separate line.'));
      break;
    }
  }
  parent::validateForm($form, $form_state);
}