function template_preprocess_update_report in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/update/update.report.inc \template_preprocess_update_report()
Prepares variables for project status report templates.
Default template: update-report.html.twig.
Parameters
array $variables: An associative array containing:
- data: An array of data about each project's status.
File
- core/
modules/ update/ update.report.inc, line 21 - Code required only when rendering the available updates report.
Code
function template_preprocess_update_report(&$variables) {
$data = $variables['data'];
$last = \Drupal::state()
->get('update.last_check') ?: 0;
$variables['last_checked'] = array(
'#theme' => 'update_last_check',
'#last' => $last,
// Attach the library to a variable that gets printed always.
'#attached' => array(
'library' => array(
'update/drupal.update.admin',
),
),
);
// For no project update data, populate no data message.
if (empty($data)) {
$variables['no_updates_message'] = _update_no_data();
}
$rows = array();
foreach ($data as $project) {
$project_status = array(
'#theme' => 'update_project_status',
'#project' => $project,
);
// Build project rows.
if (!isset($rows[$project['project_type']])) {
$rows[$project['project_type']] = array(
'#type' => 'table',
'#attributes' => array(
'class' => array(
'update',
),
),
);
}
$row_key = !empty($project['title']) ? Unicode::strtolower($project['title']) : Unicode::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 UPDATE_CURRENT:
$rows[$project['project_type']][$row_key]['#attributes'] = array(
'class' => array(
'color-success',
),
);
break;
case UPDATE_UNKNOWN:
case UPDATE_FETCH_PENDING:
case UPDATE_NOT_FETCHED:
case UPDATE_NOT_SECURE:
case UPDATE_REVOKED:
case UPDATE_NOT_SUPPORTED:
$rows[$project['project_type']][$row_key]['#attributes'] = array(
'class' => array(
'color-error',
),
);
break;
case UPDATE_NOT_CHECKED:
case UPDATE_NOT_CURRENT:
default:
$rows[$project['project_type']][$row_key]['#attributes'] = array(
'class' => array(
'color-warning',
),
);
break;
}
}
$project_types = array(
'core' => t('Drupal core'),
'module' => t('Modules'),
'theme' => t('Themes'),
'module-disabled' => t('Uninstalled modules'),
'theme-disabled' => t('Uninstalled themes'),
);
$variables['project_types'] = array();
foreach ($project_types as $type_name => $type_label) {
if (!empty($rows[$type_name])) {
ksort($rows[$type_name]);
$variables['project_types'][] = array(
'label' => $type_label,
'table' => $rows[$type_name],
);
}
}
}