You are here

public function ValidateFormBase::buildForm in Node Accessibility 8

Form constructor.

Parameters

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

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

Return value

array The form structure.

Overrides FormInterface::buildForm

File

src/Form/ValidateFormBase.php, line 82

Class

ValidateFormBase
Base Form controller for the node_accessibility entity validate forms.

Namespace

Drupal\node_accessibility\Form

Code

public function buildForm(array $form, FormStateInterface $form_state, $node = NULL, $node_revision = NULL) {
  $this->nodeId = $node;
  $this->nodeRevisionId = $node_revision;
  $this->nodeSettings = TypeSettingsStorage::loadByNode($this->nodeId);
  $form['fieldset_results'] = [
    '#type' => 'details',
    '#title' => $this
      ->t('Validation Results'),
    '#tree' => TRUE,
    '#open' => TRUE,
  ];
  $form['fieldset_results']['value_results'] = [
    '#markup' => '',
  ];
  $existing_value_results = $form_state
    ->get('fieldset_results][value_results');
  if (is_null($existing_value_results)) {
    $form['fieldset_results']['value_results']['#markup'] = 'There are no validation results available for this node.';
    $settings = TypeSettingsStorage::loadByNodeAsArray($node);
    $method = QuailApiSettings::get_validation_methods($settings['method']);
    if (is_array($method) && $method['database']) {
      $node_object = Node::load($node);
      if (!is_null($node_revision) && $node_object->vid->value != $node_revision) {
        $entity_type = $node_object
          ->getEntityTypeId();
        $node_object = $this->entityTypeManager
          ->getStorage($entity_type)
          ->loadRevision($node_revision);
        unset($entity_type);
      }
      $existing_database_results = ProblemsStorage::load_problems([
        'nid' => $node,
        'vid' => $node_object->vid->value,
      ]);
      if (!empty($existing_database_results)) {
        unset($form['fieldset_results']['value_results']['#markup']);
        $severitys = QuailApiSettings::get_severity();
        $restructured_results = ProblemsStorage::restructure_results($node, $node_object->vid->value, $severitys);
        foreach ($restructured_results as $severity => $severity_results) {
          $form['fieldset_results']['value_results'][$severity] = [
            '#theme' => 'quail_api_results',
            '#quail_severity_id' => $severity,
            '#quail_severity_array' => $severitys[$severity],
            '#quail_severity_results' => $severity_results,
            '#quail_markup_format' => $settings['format_results'],
            '#quail_title_block' => $settings['title_block'],
            '#quail_display_title' => TRUE,
            '#attached' => [
              'library' => [
                'node_accessibility/results-theme',
              ],
            ],
          ];
        }
      }
    }
  }
  else {
    $form['fieldset_results']['value_results']['#markup'] = $existing_value_results;
  }
  $form['actions'] = [
    '#type' => 'actions',
  ];
  if (\Drupal::currentUser()
    ->hasPermission('perform node accessibility validation')) {
    $form['actions']['submit_validate'] = array(
      '#type' => 'submit',
      '#value' => $this
        ->t('Validate'),
    );
  }
  return $form;
}