You are here

protected function W3CLogController::buildValidationDetailDisplay in W3C Validator 8

Builds the details of validation results for the current row.

Parameters

array $validation: An array of preprocess validation values for that page.

Return value

array A formAPI array representing the details of validation results, ready to display.

1 call to W3CLogController::buildValidationDetailDisplay()
W3CLogController::overview in src/Controller/W3CLogController.php
Return the 'overview' page.

File

src/Controller/W3CLogController.php, line 226

Class

W3CLogController
Controller routines for w3c_validator module validation log routes.

Namespace

Drupal\w3c_validator\Controller

Code

protected function buildValidationDetailDisplay(array $validation) {

  // Build the container for details results.
  $display = [
    '#prefix' => '<div class="fieldset-wrapper analysis-results">',
    '#suffix' => '</div>',
  ];

  // Build the title according to validity.
  if ($validation['validity']) {
    $output = $this
      ->t('This document was successfully checked !');
  }
  else {
    $output = $this
      ->t('Errors found while checking this document !');
  }
  $display['message'] = [
    '#prefix' => '<h2 class="message ' . $validation['class'] . '">',
    '#suffix' => '</h2>',
    '#markup' => $output,
  ];

  // Build rows for details summary table.
  // Render results.
  $uri = Url::fromUri('base:' . $validation['uri'], [
    'absolute' => TRUE,
  ]);
  $rows[] = [
    $this
      ->t('Uri'),
    Link::fromTextAndUrl($uri
      ->toString(), $uri),
  ];
  $rows[] = [
    $this
      ->t('Validity'),
    $validation['status'],
  ];
  $url = Url::fromUri($this->w3cProcessor
    ->getValidatorUrl(), [
    'query' => [
      'doc' => $uri
        ->toString(),
    ],
    'attributes' => [
      'target' => '_new',
    ],
  ]);
  $rows[] = [
    $this
      ->t('Validator results'),
    Link::fromTextAndUrl($url
      ->toString(), $url),
  ];
  $rows[] = [
    $this
      ->t('Doctype'),
    $validation['doctype'],
  ];
  $rows[] = [
    $this
      ->t('Summary'),
    $validation['result'],
  ];
  $display['detail-table'] = [
    '#type' => 'table',
    '#rows' => $rows,
    '#attributes' => [
      'class' => 'report',
    ],
    '#empty' => $this
      ->t('No data to display.'),
  ];

  // Display errors.
  $display['errors-title'] = [
    '#prefix' => '<h2>',
    '#suffix' => '</h2>',
    '#markup' => $this
      ->t('Errors'),
  ];
  $validation['errors'] = is_array($validation['errors']) ? $validation['errors'] : unserialize($validation['errors']);
  if (is_array($validation['errors']) && !empty($validation['errors'])) {

    /** @var \HtmlValidator\Message $error */
    foreach ($validation['errors'] as $id => $error) {
      $display['error'][$id] = [
        '#prefix' => '<div class="message-wrapper message-error">',
        '#suffix' => '</div>',
        'message' => [
          '#prefix' => '<div class="message">',
          '#suffix' => '</div>',
          '#markup' => '<span class="where">' . $this
            ->t('Line @line, Column @col:', [
            '@line' => $error
              ->getFirstLine(),
            '@col' => $error
              ->getFirstColumn(),
          ]) . '</span> <span class="descr">' . $this
            ->t('@descr', [
            '@descr' => $error
              ->getText(),
          ]) . '</span>',
        ],
        'source' => [
          '#prefix' => '<div class="source">',
          '#suffix' => '</div>',
          '#markup' => '<pre>' . $this
            ->highlightExtract($error
            ->getExtract(), $error
            ->getHighlightStart(), $error
            ->getHighlightLength()) . '</pre>',
        ],
      ];
    }
  }
  else {
    $display['error'] = [
      '#prefix' => '<div>',
      '#suffix' => '</div>',
      '#markup' => $this
        ->t('No errors found'),
    ];
  }

  // Display warnings.
  $display['warnings-title'] = [
    '#prefix' => '<h2>',
    '#suffix' => '</h2>',
    '#markup' => $this
      ->t('Warnings'),
  ];
  $validation['warnings'] = is_array($validation['warnings']) ? $validation['warnings'] : unserialize($validation['warnings']);
  if (is_array($validation['warnings']) && !empty($validation['warnings'])) {

    /** @var \HtmlValidator\Message $warning */
    foreach ($validation['warnings'] as $id => $warning) {
      $display['warning'][$id] = [
        '#prefix' => '<div class="message-wrapper message-warning">',
        '#suffix' => '</div>',
        'message' => [
          '#prefix' => '<div class="message">',
          '#suffix' => '</div>',
          '#markup' => '<span class="where">' . $this
            ->t('Line @line, Column @col:', [
            '@line' => $warning
              ->getFirstLine(),
            '@col' => $warning
              ->getFirstColumn(),
          ]) . '</span> <span class="descr">' . $this
            ->t('@descr', [
            '@descr' => $warning
              ->getText(),
          ]) . '</span>',
        ],
        'source' => [
          '#prefix' => '<div class="source">',
          '#suffix' => '</div>',
          '#markup' => '<pre>' . $this
            ->highlightExtract($warning
            ->getExtract(), $warning
            ->getHighlightStart(), $warning
            ->getHighlightLength()) . '</pre>',
        ],
      ];
    }
  }
  else {
    $display['warning'] = [
      '#prefix' => '<div>',
      '#suffix' => '</div>',
      '#markup' => $this
        ->t('No warnings found'),
    ];
  }

  // Display messages.
  $display['infos-title'] = [
    '#prefix' => '<h2>',
    '#suffix' => '</h2>',
    '#markup' => $this
      ->t('Infos'),
  ];
  $validation['infos'] = is_array($validation['infos']) ? $validation['infos'] : unserialize($validation['infos']);
  if (is_array($validation['infos']) && !empty($validation['infos'])) {

    /** @var \HtmlValidator\Message $info */
    foreach ($validation['infos'] as $id => $info) {
      $display['info'][$id] = [
        '#prefix' => '<div class="message-wrapper message-info">',
        '#suffix' => '</div>',
        'message' => [
          '#prefix' => '<div class="message">',
          '#suffix' => '</div>',
          '#markup' => '<span class="where">' . $this
            ->t('Line @line, Column @col:', [
            '@line' => $info
              ->getFirstLine(),
            '@col' => $info
              ->getFirstColumn(),
          ]) . '</span> <span class="descr">' . $this
            ->t('@descr', [
            '@descr' => $info
              ->getText(),
          ]) . '</span>',
        ],
        'source' => [
          '#prefix' => '<div class="source">',
          '#suffix' => '</div>',
          '#markup' => '<pre>' . $this
            ->highlightExtract($info
            ->getExtract(), $info
            ->getHighlightStart(), $info
            ->getHighlightLength()) . '</pre>',
        ],
      ];
    }
  }
  else {
    $display['infos'] = [
      '#prefix' => '<div>',
      '#suffix' => '</div>',
      '#markup' => $this
        ->t('No information found'),
    ];
  }
  return $display;
}