You are here

public function ChecklistController::index in Security Review 8

Creates the Run & Review page.

Return value

array The 'Run & Review' page's render array.

1 string reference to 'ChecklistController::index'
security_review.routing.yml in ./security_review.routing.yml
security_review.routing.yml

File

src/Controller/ChecklistController.php, line 84

Class

ChecklistController
The class of the 'Run & Review' page's controller.

Namespace

Drupal\security_review\Controller

Code

public function index() {
  $run_form = [];

  // If the user has the required permissions, show the RunForm.
  if ($this
    ->currentUser()
    ->hasPermission('run security checks')) {

    // Get the Run form.
    $run_form = $this
      ->formBuilder()
      ->getForm('Drupal\\security_review\\Form\\RunForm');

    // Close the Run form if there are results.
    if ($this->securityReview
      ->getLastRun() > 0) {
      $run_form['run_form']['#open'] = FALSE;
    }
  }

  // Print the results if any.
  if ($this->securityReview
    ->getLastRun() <= 0) {

    // If they haven't configured the site, prompt them to do so.
    if (!$this->securityReview
      ->isConfigured()) {
      $this->messenger
        ->addWarning($this
        ->t('It appears this is your first time using the Security Review checklist. Before running the checklist please review the settings page at <a href=":url">admin/reports/security-review/settings</a> to set which roles are untrusted.', [
        ':url' => Url::fromRoute('security_review.settings')
          ->toString(),
      ]), 'warning');
    }
  }
  return [
    $run_form,
    $this
      ->results(),
  ];
}