You are here

public function ValidateFormBase::submitForm in Node Accessibility 8

Form submission handler.

Parameters

array $form: An associative array containing the structure of the form.

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

Overrides FormInterface::submitForm

File

src/Form/ValidateFormBase.php, line 170

Class

ValidateFormBase
Base Form controller for the node_accessibility entity validate forms.

Namespace

Drupal\node_accessibility\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  if (empty($this->nodeId)) {
    return;
  }
  if (is_null($this->nodeSettings)) {
    $this->nodeSettings = TypeSettingsStorage::loadByNode($this->nodeId);
  }
  if (is_null($this->nodeRevisionId)) {
    $results = PerformValidation::nodes([
      $this->nodeId,
    ], NULL, NULL, $this->nodeSettings
      ->getStandards());
  }
  else {
    $results = PerformValidation::node_revisions([
      $this->nodeRevisionId => $this->nodeId,
    ], NULL, NULL, $this->nodeSettings
      ->getStandards());
  }
  if (empty($this->nodeSettings
    ->getNodeType())) {
    return;
  }
  $enabled = $this->nodeSettings
    ->getEnabled();
  if (empty($enabled) || $enabled == 'disabled') {
    return;
  }
  if (array_key_exists($this->nodeId, $results) && !empty($results[$this->nodeId])) {
    $severitys = QuailApiSettings::get_severity();
    $methods = QuailApiSettings::get_validation_methods();
    $result = reset($results[$this->nodeId]);
    unset($results);
    if (empty($result['report'])) {
      unset($result);
      $markup = $this
        ->t('No accessibility violations have been detected.');
    }
    else {
      $reports = $result['report'];
      $total = $result['total'];
      unset($result);
      $format_results = $this->nodeSettings
        ->getFormatResults();
      if (empty($format_results)) {
        $format_results = \Drupal::config('quail_api.settings')
          ->get('filter_format');
      }
      $title_block = $this->nodeSettings
        ->getFormatResults();
      if (empty($title_block)) {
        $title_block = \Drupal::config('quail_api.settings')
          ->get('title_block');
      }
      if (empty($title_block)) {
        $title_block = 'h3';
      }

      // the reason this is converted to markup is because the generated
      // markup is intended to be saved to the database. This is not a
      // cache, but a renderred copy of the data for archival and
      // validation purposes.
      $markup = '';
      foreach ($reports as $severity => $severity_results) {
        $theme_array = [
          '#theme' => 'quail_api_results',
          '#quail_severity_id' => $severity,
          '#quail_severity_array' => $severitys[$severity],
          '#quail_severity_results' => $severity_results,
          '#quail_markup_format' => $format_results,
          '#quail_title_block' => $title_block,
          '#quail_display_title' => TRUE,
          '#attached' => [
            'library' => [
              'node_accessibility/results-theme',
            ],
          ],
        ];
        $markup .= \Drupal::service('renderer')
          ->render($theme_array, FALSE);
      }
    }
    $form_state
      ->set('fieldset_results][value_results', $markup);
  }
  $form_state
    ->setRebuild(TRUE);
  $form_state
    ->setSubmitted(TRUE);
  $form_state
    ->setExecuted(TRUE);
}