Issue #2151101 by joelpittet, c4rl, IshaDakota, pplantinga, gnuget, longwave, jeanfei, sbudker1: Convert theme_status_report() to Twig

8.0.x
webchick 2014-01-25 21:11:21 -08:00
parent 297972bac7
commit e9a240b4b9
3 changed files with 51 additions and 29 deletions

View File

@ -268,7 +268,9 @@ function theme_system_admin_index($variables) {
}
/**
* Returns HTML for the status report.
* Prepares variables for status report template.
*
* Default template: status-report.html.twig.
*
* This theme function is dependent on install.inc being loaded, because
* that's where the constants are defined.
@ -288,8 +290,7 @@ function theme_system_admin_index($variables) {
*
* @ingroup themeable
*/
function theme_status_report($variables) {
$requirements = $variables['requirements'];
function template_preprocess_status_report(&$variables) {
$severities = array(
REQUIREMENT_INFO => array(
'title' => t('Info'),
@ -308,11 +309,8 @@ function theme_status_report($variables) {
'class' => 'error',
),
);
$output = '<table class="system-status-report"><thead><tr class="visually-hidden">';
$output .= '<th>' . t('Status') . '</th><th>' . t('Component') . '</th><th>' . t('Details') . '</th>';
$output .= '</tr></thead><tbody>';
foreach ($requirements as $requirement) {
foreach ($variables['requirements'] as $i => $requirement) {
// Always use the explicit requirement severity, if defined. Otherwise,
// default to REQUIREMENT_OK in the installer to visually confirm that
// installation requirements are met. And default to REQUIREMENT_INFO to
@ -326,29 +324,9 @@ function theme_status_report($variables) {
else {
$severity = $severities[REQUIREMENT_INFO];
}
// hook_requirements does not require value to be set. Set to null if not:
if (isset($requirement['value'])) {
$value = $requirement['value'];
}
else {
$value = NULL;
}
$severity['icon'] = '<div title="' . $severity['title'] . '"><span class="visually-hidden">' . $severity['title'] . '</span></div>';
// Output table rows.
$output .= '<tr class="' . $severity['class'] . '">';
$output .= '<td class="status-icon">' . $severity['icon'] . '</td>';
$output .= '<td class="status-title">' . $requirement['title'] . '</td>';
$output .= '<td class="status-value">' . $value;
if (!empty($requirement['description'])) {
$output .= '<div class="description">' . $requirement['description'] . '</div>';
}
$output .= '</td></tr>';
$variables['requirements'][$i]['severity_class'] = $severity['class'];
$variables['requirements'][$i]['severity_title'] = $severity['title'];
}
$output .= '</tbody></table>';
return $output;
}
/**

View File

@ -177,6 +177,7 @@ function system_theme() {
'status_report' => array(
'variables' => array('requirements' => NULL),
'file' => 'system.admin.inc',
'template' => 'status-report',
),
'admin_page' => array(
'variables' => array('blocks' => NULL),

View File

@ -0,0 +1,43 @@
{#
/**
* Default theme implementation for the status report.
*
* Available variables:
* - requirements: Contains multiple requirement instances.
* Each requirement contains:
* - title: The title of the requirement.
* - value: (optional) The requirement's status.
* - description: (optional) The requirement's description.
* - severity_title: The title of the severity.
* - severity_class: The HTML class of the severity.
*
* @see template_preprocess_status_report()
*
* @ingroup themeable
*/
#}
<table class="system-status-report">
<thead>
<tr class="visually-hidden">
<th>{{ 'Status'|t }}</th><th>{{ 'Component'|t }}</th><th>{{ 'Details'|t }}</th>
</tr>
</thead>
<tbody>
{% for requirement in requirements %}
<tr class="{{ requirement.severity_class }}">
<td class="status-icon">
<div title="{{ requirement.severity_title }}">
<span class="visually-hidden">{{ requirement.severity_title }}</span>
</div>
</td>
<td class="status-title">{{ requirement.title }}</td>
<td class="status-value">
{{ requirement.value }}
{% if requirement.description %}
<div class="description">{{ requirement.description }}</div>
{% endif %}
</td>
</tr>
{% endfor %}
</tbody>
</table>