You are here

private function UserInputParserTrait::validateHeaders in Warmer 8

Same name and namespace in other branches
  1. 2.x modules/warmer_cdn/src/Plugin/warmer/UserInputParserTrait.php \Drupal\warmer_cdn\Plugin\warmer\UserInputParserTrait::validateHeaders()

Validate the input for the headers.

Parameters

array $form: The form.

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

2 calls to UserInputParserTrait::validateHeaders()
CdnWarmer::validateConfigurationForm in modules/warmer_cdn/src/Plugin/warmer/CdnWarmer.php
Form validation handler.
SitemapWarmer::validateConfigurationForm in modules/warmer_cdn/src/Plugin/warmer/SitemapWarmer.php
Form validation handler.

File

modules/warmer_cdn/src/Plugin/warmer/UserInputParserTrait.php, line 44

Class

UserInputParserTrait
Common methods to parse user input.

Namespace

Drupal\warmer_cdn\Plugin\warmer

Code

private function validateHeaders(array $form, FormStateInterface $form_state) {
  $headers = $form_state
    ->getValue('headers');
  $lines = array_filter(explode("\n", $headers));

  // Count the number of lines that have colons.
  $colons = array_reduce($lines, function ($carry, $line) {
    return strpos($line, ':') === FALSE ? $carry : $carry + 1;
  }, 0);
  if ($colons && $colons !== count($lines)) {
    $form_state
      ->setError($form['headers'], $this
      ->t('All headers must have a colon. Follow the format: <code>the-name: the-value</code>'));
  }
}