Exemplo n.º 1
0
 /**
  * Submit handler for the HTML tag validation.
  */
 function validateTags(array $form, FormStateInterface $form_state)
 {
     $validation_messages = array();
     $field_count = 0;
     foreach ($form_state->getValues() as $field => $value) {
         if (is_array($value) && isset($value['translation'])) {
             if (!empty($value['translation'])) {
                 $tags_validated = $this->compareHTMLTags($value['source'], $value['translation']);
                 if ($tags_validated) {
                     $validation_messages[$field] = $tags_validated;
                     $field_count++;
                 }
             }
         }
     }
     if ($field_count > 0) {
         drupal_set_message(t('HTML tag validation failed for @count field(s).', array('@count' => $field_count)), 'error');
     } else {
         drupal_set_message(t('Validation completed successfully.'));
     }
     $form_state->set('validation_messages', $validation_messages);
     $request = \Drupal::request();
     $url = $this->entity->urlInfo('canonical');
     if ($request->query->has('destination')) {
         $destination = $request->query->get('destination');
         $request->query->remove('destination');
         $url->setOption('query', array('destination' => $destination));
     }
     $form_state->setRedirectUrl($url);
     $form_state->setRebuild();
 }