You are here

function template_preprocess_hacked_report in Hacked! 8.2

Prepares variables for hacked status report templates.

Default template: hacked-report.html.twig.

Parameters

array $variables: An associative array containing:

  • data: An array of data about each project's status.

File

./hacked.report.inc, line 125

Code

function template_preprocess_hacked_report(&$variables) {
  $data = $variables['data'];
  $last = \Drupal::state()
    ->get('hacked.last_check') ?: 0;
  $variables['last_checked'] = [
    '#theme' => 'update_last_check',
    '#last' => $last,
    // Attach the library to a variable that gets printed always.
    '#attached' => [
      'library' => [
        'update/drupal.update.admin',
      ],
    ],
  ];

  // For no project update data, populate no data message.
  if (empty($data)) {
    $destination = \Drupal::destination()
      ->getAsArray();
    $variables['no_updates_message'] = t('No hacked information available. <a href=":check_manually">check manually</a>.', array(
      ':run_cron' => Url::fromRoute('system.run_cron', [], [
        'query' => $destination,
      ]),
      ':check_manually' => Url::fromRoute('hacked.manual_status', [], [
        'query' => $destination,
      ]),
    ));
  }
  $rows = [];
  foreach ($data as $project) {
    if (!isset($project['status'])) {
      continue;
    }
    $project_status = [
      '#theme' => 'update_project_status',
      '#project' => $project,
    ];

    // Build project rows.
    if (!isset($rows[$project['project_type']])) {
      $rows[$project['project_type']] = [
        '#type' => 'table',
        '#attributes' => [
          'class' => [
            'update',
          ],
        ],
      ];
    }
    $row_key = !empty($project['title']) ? mb_strtolower($project['title']) : mb_strtolower($project['name']);

    // Add the project status row and details.
    $rows[$project['project_type']][$row_key]['status'] = $project_status;

    // Add project status class attribute to the table row.
    switch ($project['status']) {
      case HACKED_STATUS_UNHACKED:
        $rows[$project['project_type']][$row_key]['#attributes'] = [
          'class' => [
            'color-success',
          ],
        ];
        break;
      case HACKED_STATUS_HACKED:
        $rows[$project['project_type']][$row_key]['#attributes'] = [
          'class' => [
            'color-error',
          ],
        ];
        break;
      case HACKED_STATUS_UNCHECKED:
      default:
        $rows[$project['project_type']][$row_key]['#attributes'] = [
          'class' => [
            'color-warning',
          ],
        ];
        break;
    }
  }
  $project_types = [
    'core' => t('Drupal core'),
    'module' => t('Modules'),
    'theme' => t('Themes'),
    'module-disabled' => t('Uninstalled modules'),
    'theme-disabled' => t('Uninstalled themes'),
  ];
  $variables['project_types'] = [];
  foreach ($project_types as $type_name => $type_label) {
    if (!empty($rows[$type_name])) {
      ksort($rows[$type_name]);
      $variables['project_types'][] = [
        'label' => $type_label,
        'table' => $rows[$type_name],
      ];
    }
  }
}