You are here

function template_preprocess_run_and_review in Security Review 8

Preprocesses variables for template 'run_and_review'.

File

./security_review.module, line 122
Site security review and reporting Drupal module.

Code

function template_preprocess_run_and_review(&$variables) {

  // Get icon list.
  $icons_root = '/core/misc/icons/';
  $variables['icons'] = [
    'success' => $icons_root . '73b355/check.svg',
    'warning' => $icons_root . 'e29700/warning.svg',
    'fail' => $icons_root . 'e32700/error.svg',
  ];

  // Generate full URLs.
  foreach ($variables['icons'] as $icon => $path) {
    $variables['icons'][$icon] = Url::fromUserInput($path)
      ->setAbsolute()
      ->toString();
  }

  // Format date.
  $variables['date'] = \Drupal::service('date.formatter')
    ->format($variables['date']);

  // Convert check result integers to strings.
  foreach ($variables['checks'] as &$check) {
    if (isset($check['result'])) {
      switch ($check['result']) {
        case CheckResult::SUCCESS:
          $check['result'] = 'success';
          break;
        case CheckResult::FAIL:
          $check['result'] = 'fail';
          break;
        case CheckResult::WARN:
          $check['result'] = 'warning';
          break;
        case CheckResult::INFO:
          $check['result'] = 'info';
          break;
      }
    }
  }
}