Exemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function validateConfigurationForm(array &$form, FormStateInterface $form_state)
 {
     parent::validateConfigurationForm($form, $form_state);
     $spaces = str_replace('/', '\\/', trim($form_state->getValues()['spaces']));
     if ($spaces !== '' && @preg_match('/(' . $spaces . ')+/u', '') === FALSE) {
         $form_state->setError($form['spaces'], $form['spaces']['#title'] . ': ' . $this->t('The entered text is no valid regular expression.'));
     }
 }
Exemplo n.º 2
0
 /**
  * {@inheritdoc}
  */
 public function validateConfigurationForm(array &$form, FormStateInterface $form_state)
 {
     parent::validateConfigurationForm($form, $form_state);
     $ignorable = str_replace('/', '\\/', $form_state->getValues()['ignorable']);
     if (@preg_match('/(' . $ignorable . ')+/u', '') === FALSE) {
         $el = $form['ignorable'];
         $form_state->setError($el, $el['#title'] . ': ' . $this->t('The entered text is no valid regular expression.'));
     }
 }
Exemplo n.º 3
0
 /**
  * {@inheritdoc}
  */
 public function validateConfigurationForm(array &$form, FormStateInterface $form_state)
 {
     parent::validateConfigurationForm($form, $form_state);
     $tags = trim($form_state->getValue('tags'));
     if (!$tags) {
         $form_state->setValue('tags', array());
         return;
     }
     $errors = array();
     try {
         $parser = new Parser();
         $tags = $parser->parse($tags);
         if (!is_array($tags)) {
             $errors[] = $this->t('Tags is not a valid YAML map. See @link for information on how to write correctly formed YAML.', array('@link' => 'http://yaml.org'));
             $tags = array();
         }
     } catch (ParseException $exception) {
         $errors[] = $this->t('Tags is not valid YAML. See @link for information on how to write correctly formed YAML.', array('@link' => 'http://yaml.org'));
         $tags = array();
     }
     foreach ($tags as $key => $value) {
         $tag = "<{$key}>";
         if (is_array($value)) {
             $errors[] = $this->t("Boost value for tag @tag can't be an array.", array('@tag' => $tag));
         } elseif (!is_numeric($value)) {
             $errors[] = $this->t("Boost value for tag @tag must be numeric.", array('@tag' => $tag));
         } elseif ($value < 0) {
             $errors[] = $this->t('Boost value for tag @tag must be non-negative.', array('@tag' => $tag));
         } elseif ($value == 1) {
             unset($tags[$key]);
         } else {
             $tags[$key] = (double) $value;
         }
     }
     $form_state->setValue('tags', $tags);
     if ($errors) {
         $form_state->setError($form['tags'], implode("<br />\n", $errors));
     }
 }