You are here

public function W3CLogController::overview in W3C Validator 8

Return the 'overview' page.

This page displays a report of all pages, exposing their current validation state. Validation errors are displayed if existing as well as a form to re-validate it all if necessary.

Return value

array A render array containing our 'overview report' page content.

1 string reference to 'W3CLogController::overview'
w3c_validator.routing.yml in ./w3c_validator.routing.yml
w3c_validator.routing.yml

File

src/Controller/W3CLogController.php, line 76

Class

W3CLogController
Controller routines for w3c_validator module validation log routes.

Namespace

Drupal\w3c_validator\Controller

Code

public function overview() {
  $output = [
    '#prefix' => '<div id="foobar">',
    '#suffix' => '</div>',
  ];
  $rows = [];

  // Add re-validation form on top.
  $output['operations'] = $this->formBuilder
    ->getForm('Drupal\\w3c_validator\\Form\\W3CValidatorOperationForm');

  // Retrieve all site pages.
  $pages = $this->w3cProcessor
    ->findAllPages();

  // Retrieve all validated pages.
  $all_validated_pages = $this->w3cProcessor
    ->findAllValidatedPages();

  // Loop over result to build display.
  foreach ($pages as $url => $page) {

    // Build validation result.
    $validation = $this
      ->buildValidationResult($all_validated_pages, $url);

    // Build the result display using form API.
    $row = [];
    $row[$url]['summary'] = $this
      ->buildValidationDisplay($page, $validation);
    if (isset($validation['status']) && $validation['status'] != $this
      ->t('Unknown')) {
      $row[$url]['details'] = $this
        ->buildValidationDetailDisplay($validation);
    }

    // Render results.
    $rows[] = [
      'data' => [
        [
          'data' => $this->renderer
            ->render($row),
          'class' => 'w3c_validator-wrapper collapsed',
        ],
      ],
      'class' => [
        $validation['class'],
      ],
    ];
  }
  $output['pages'] = [
    '#type' => 'table',
    '#rows' => $rows,
    '#attributes' => [
      'id' => 'w3c-report',
    ],
    '#empty' => $this
      ->t('No data to display.'),
  ];
  $output['#attached']['library'][] = 'w3c_validator/w3c_validator.report';
  return $output;
}