commit 641be06f1ba1ebbf81ef00c64fe936b4368106e7 Author: Joel Pittet Date: Fri Apr 12 23:41:41 2013 -0700 report_update diff --git a/core/modules/update/templates/update-report.html.twig b/core/modules/update/templates/update-report.html.twig index 90e1c80..cf9e711 100644 --- a/core/modules/update/templates/update-report.html.twig +++ b/core/modules/update/templates/update-report.html.twig @@ -11,4 +11,74 @@ * * @ingroup themeable */ +{{ dump(project_types) }} #} + +{% for project_type in project_types %} +

{{ project_type.label }}

+ + + {% for project in project_type.projects %} + + + + + + {% endfor %} + +
+
+ {% if project.status_label is not empty %} + {{ project.status_label }} + {% else %} + {{ project.status }} + {% endif %} + {{ project.icon }} +
+ +
+ {{ project.title }} {{ project.existing_version }} + {% if project.install_type == 'dev' and project.datestamp is not empty %} + ({{ project.datestamp }}) + {% endif %} +
+ + {% if project.versions %} +
+ {% for version in project.versions %} + {{ version }} + {% endfor %} +
+ {% endif %} + +
+ {% if project.extra %} +
+ {% for extra in project.extra %} + + {{ extra.label }}: {{ extra.data }} +
+ {% endfor %} +
+ {% endif %} + +
+ {{ 'Includes'|t }}: + {{ project.includes }} +
+ + {% if project.base_themes %} +
+ {{ 'Depends on: !basethemes'|t({'!basethemes': project.base_themes|join(', ')}) }} +
+ {% endif %} + + {% if project.sub_themes %} +
+ {{ 'Required by: %subthemes'|t({'%subthemes': project.sub_themes|join(', ')}) }} +
+ {% endif %} + + +
+{% endfor %} diff --git a/core/modules/update/update.module b/core/modules/update/update.module index e9b8663..de034b5 100644 --- a/core/modules/update/update.module +++ b/core/modules/update/update.module @@ -263,10 +263,11 @@ function update_theme() { ), 'update_report' => array( 'variables' => array('data' => NULL), - // 'template' => 'update-report', + 'file' => 'update.report.inc', + 'template' => 'update-report', ), 'update_version' => array( - 'variables' => array('version' => NULL, 'tag' => NULL), + 'variables' => array('version' => NULL, 'tag' => NULL, 'class' => array()), 'file' => 'update.report.inc', 'template' => 'update-version', ), diff --git a/core/modules/update/update.report.inc b/core/modules/update/update.report.inc index 6bbd9cd..74bd377 100644 --- a/core/modules/update/update.report.inc +++ b/core/modules/update/update.report.inc @@ -47,18 +47,14 @@ function update_status() { /** * Prepares variables the project status report. * - * Default template: container.html.twig. + * Default template: update-report.html.twig. * * @param array $variables * An associative array containing: * - data: An array of data about each project's status. - * */ -function theme_update_report($variables) { - $data = $variables['data']; - - $output = ''; - $header = array(); +function template_preprocess_update_report(&$variables) { + $projects = $variables['data']; $rows = array(); $notification_level = config('update.settings')->get('notification.threshold'); @@ -66,63 +62,100 @@ function theme_update_report($variables) { // Create an array of status values keyed by module or theme name, since // we'll need this while generating the report if we have to cross reference // anything (e.g. subthemes which have base themes missing an update). - foreach ($data as $project) { + foreach ($projects as $project) { foreach ($project['includes'] as $key => $name) { $status[$key] = $project['status']; } } - foreach ($data as $project) { + foreach ($projects as $project) { switch ($project['status']) { case UPDATE_CURRENT: $class = 'ok'; - $icon = theme('image', array('uri' => 'core/misc/watchdog-ok.png', 'width' => 18, 'height' => 18, 'alt' => t('ok'), 'title' => t('ok'))); + $icon = array( + '#theme' => 'image', + '#uri' => 'core/misc/watchdog-ok.png', + '#width' => 18, + '#height' => 18, + '#alt' => t('ok'), + '#title' => t('ok'), + ); break; case UPDATE_UNKNOWN: case UPDATE_FETCH_PENDING: case UPDATE_NOT_FETCHED: $class = 'unknown'; - $icon = theme('image', array('uri' => 'core/misc/watchdog-warning.png', 'width' => 18, 'height' => 18, 'alt' => t('warning'), 'title' => t('warning'))); + $icon = array( + '#theme' => 'image', + '#uri' => 'core/misc/watchdog-warning.png', + '#width' => 18, + '#height' => 18, + '#alt' => t('warning'), + '#title' => t('warning'), + ); break; case UPDATE_NOT_SECURE: case UPDATE_REVOKED: case UPDATE_NOT_SUPPORTED: $class = 'error'; - $icon = theme('image', array('uri' => 'core/misc/watchdog-error.png', 'width' => 18, 'height' => 18, 'alt' => t('error'), 'title' => t('error'))); + $icon = array( + '#theme' => 'image', + '#uri' => 'core/misc/watchdog-error.png', + '#width' => 18, + '#height' => 18, + '#alt' => t('error'), + '#title' => t('error'), + ); break; case UPDATE_NOT_CHECKED: case UPDATE_NOT_CURRENT: default: $class = 'warning'; - $icon = theme('image', array('uri' => 'core/misc/watchdog-warning.png', 'width' => 18, 'height' => 18, 'alt' => t('warning'), 'title' => t('warning'))); + $icon = array( + '#theme' => 'image', + '#uri' => 'core/misc/watchdog-warning.png', + '#width' => 18, + '#height' => 18, + '#alt' => t('warning'), + '#title' => t('warning'), + ); break; } - $row = '
'; - $status_label = theme('update_status_label', array('status' => $project['status'])); - $row .= !empty($status_label) ? $status_label : check_plain($project['reason']); - $row .= '' . $icon . ''; - $row .= "
\n"; + $project['icon'] = $icon; + $project['status_label'] = array( + '#theme' => 'update_status_label', + '#status' => $project['status'], + ); + + if (!empty($project['reason'])) { + $project['reason'] = check_plain($project['reason']); + } + + // Store locally for key later. + $project_title = ''; - $row .= '
'; + // Set the project title. if (isset($project['title'])) { + $project_title = $project['title']; if (isset($project['link'])) { - $row .= l($project['title'], $project['link']); + $project['title'] = l($project['title'], $project['link']); } else { - $row .= check_plain($project['title']); + $project['title'] = check_plain($project['title']); } } else { - $row .= check_plain($project['name']); + $project['title'] = check_plain($project['name']); } - $row .= ' ' . check_plain($project['existing_version']); - if ($project['install_type'] == 'dev' && !empty($project['datestamp'])) { - $row .= ' (' . format_date($project['datestamp'], 'custom', 'Y-M-d') . ')'; + + $project['existing_version'] = check_plain($project['existing_version']); + + if (!empty($project['datestamp'])) { + $project['datestamp'] = format_date($project['datestamp'], 'custom', 'Y-M-d'); } - $row .= "
\n"; - $versions_inner = ''; + $versions_inner = array(); $security_class = array(); $version_class = array(); if (isset($project['recommended'])) { @@ -132,7 +165,10 @@ function theme_update_report($variables) { // If there's only 1 security update and it has the same version we're // recommending, give it the same CSS class as if it was recommended, // but don't print out a separate "Recommended" line for this project. - if (!empty($project['security updates']) && count($project['security updates']) == 1 && $project['security updates'][0]['version'] === $project['recommended']) { + if (!empty($project['security updates']) + && count($project['security updates']) == 1 + && $project['security updates'][0]['version'] === $project['recommended'] + ) { $security_class[] = 'version-recommended'; $security_class[] = 'version-recommended-strong'; } @@ -151,88 +187,89 @@ function theme_update_report($variables) { ) { $version_class[] = 'version-recommended-strong'; } - $versions_inner .= theme('update_version', array( - 'version' => $project['releases'][$project['recommended']], - 'tag' => t('Recommended version:'), - 'attributes' => array('class' => $version_class), - )); + $versions_inner[] = array( + '#theme' => 'update_version', + '#version' => $project['releases'][$project['recommended']], + '#tag' => t('Recommended version:'), + '#class' => $version_class, + ); } // Now, print any security updates. if (!empty($project['security updates'])) { $security_class[] = 'version-security'; foreach ($project['security updates'] as $security_update) { - $versions_inner .= theme('update_version', array( - 'version' => $security_update, - 'tag' => t('Security update:'), - 'attributes' => array('class' => $security_class), - )); + $versions_inner[] = array( + '#theme' => 'update_version', + '#version' => $security_update, + '#tag' => t('Security update:'), + '#class' => $security_class, + ); } } } if ($project['recommended'] !== $project['latest_version']) { - $versions_inner .= theme('update_version', array( - 'version' => $project['releases'][$project['latest_version']], - 'tag' => t('Latest version:'), - 'attributes' => array('class' => array('version-latest')), - )); + $versions_inner[] = array( + '#theme' => 'update_version', + '#version' => $project['releases'][$project['latest_version']], + '#tag' => t('Latest version:'), + '#class' => array('version-latest'), + ); } if ($project['install_type'] == 'dev' && $project['status'] != UPDATE_CURRENT && isset($project['dev_version']) && $project['recommended'] !== $project['dev_version']) { - $versions_inner .= theme('update_version', array( - 'version' => $project['releases'][$project['dev_version']], - 'tag' => t('Development version:'), - 'attributes' => array('class' => array('version-latest')), - )); + $versions_inner[] = array( + '#theme' => 'update_version', + '#version' => $project['releases'][$project['dev_version']], + '#tag' => t('Development version:'), + '#class' => array('version-latest'), + ); } } if (isset($project['also'])) { foreach ($project['also'] as $also) { - $versions_inner .= theme('update_version', array( - 'version' => $project['releases'][$also], - 'tag' => t('Also available:'), - 'attributes' => array('class' => array('version-also-available')), - )); + $versions_inner[] = array( + '#theme' => 'update_version', + '#version' => $project['releases'][$also], + '#tag' => t('Also available:'), + '#class' => array('version-also-available'), + ); } } if (!empty($versions_inner)) { - $row .= "
\n" . $versions_inner . "
\n"; + $project['versions'] = $versions_inner; } - $row .= "
\n"; + if (!empty($project['extra'])) { - $row .= '
' . "\n"; - foreach ($project['extra'] as $key => $value) { - $row .= '
'; - $row .= check_plain($value['label']) . ': '; - $row .= drupal_placeholder($value['data']); - $row .= "
\n"; + foreach ($project['extra'] as &$extra_item) { + $extra_item['attributes'] = new Attribute(array('class' => $extra_item['class'])); + $extra_item['label'] = check_plain($extra_item['label']); + $extra_item['data'] = drupal_placeholder($extra_item['data']); } - $row .= "
\n"; // extra div. } - $row .= '
'; sort($project['includes']); if (!empty($project['disabled'])) { sort($project['disabled']); - // Make sure we start with a clean slate for each project in the report. - $includes_items = array(); - $row .= t('Includes:'); + $includes_items[] = t('Enabled: %includes', array('%includes' => implode(', ', $project['includes']))); $includes_items[] = t('Disabled: %disabled', array('%disabled' => implode(', ', $project['disabled']))); - $row .= theme('item_list', array('items' => $includes_items)); + + $project['includes'] = array( + '#theme' => 'item_list', + '#items' => $includes_items, + ); } else { - $row .= t('Includes: %includes', array('%includes' => implode(', ', $project['includes']))); + $project['includes'] = t('%includes', array('%includes' => implode(', ', $project['includes']))); } - $row .= "
\n"; if (!empty($project['base_themes'])) { - $row .= '
'; asort($project['base_themes']); $base_themes = array(); foreach ($project['base_themes'] as $base_key => $base_theme) { @@ -240,34 +277,34 @@ function theme_update_report($variables) { case UPDATE_NOT_SECURE: case UPDATE_REVOKED: case UPDATE_NOT_SUPPORTED: - $base_themes[] = t('%base_theme (!base_label)', array('%base_theme' => $base_theme, '!base_label' => theme('update_status_label', array('status' => $status[$base_key])))); + $base_themes[] = t('%base_theme (!base_label)', array( + '%base_theme' => $base_theme, + '!base_label' => array( + '#theme' => 'update_status_label', + '#status' => $status[$base_key], + ), + )); break; default: $base_themes[] = drupal_placeholder($base_theme); } } - $row .= t('Depends on: !basethemes', array('!basethemes' => implode(', ', $base_themes))); - $row .= "
\n"; + $project['base_themes'] = $base_themes; } if (!empty($project['sub_themes'])) { - $row .= '
'; sort($project['sub_themes']); - $row .= t('Required by: %subthemes', array('%subthemes' => implode(', ', $project['sub_themes']))); - $row .= "
\n"; } - $row .= "
\n"; // info div. + $project['attributes'] = new Attribute(array('class' => $class)); + // Build project rows. if (!isset($rows[$project['project_type']])) { $rows[$project['project_type']] = array(); } - $row_key = isset($project['title']) ? drupal_strtolower($project['title']) : drupal_strtolower($project['name']); - $rows[$project['project_type']][$row_key] = array( - 'class' => array($class), - 'data' => array($row), - ); + $row_key = !empty($project_title) ? drupal_strtolower($project_title) : drupal_strtolower($project['name']); + $rows[$project['project_type']][$row_key] = $project; } $project_types = array( @@ -277,15 +314,17 @@ function theme_update_report($variables) { 'module-disabled' => t('Disabled modules'), 'theme-disabled' => t('Disabled themes'), ); + $variables['project_types'] = array(); foreach ($project_types as $type_name => $type_label) { if (!empty($rows[$type_name])) { ksort($rows[$type_name]); - $output .= "\n

" . $type_label . "

\n"; - $output .= theme('table', array('header' => $header, 'rows' => $rows[$type_name], 'attributes' => array('class' => array('update')))); + $variables['project_types'][] = array( + 'label' => $type_label, + 'projects' => $rows[$type_name], + ); } } drupal_add_css(drupal_get_path('module', 'update') . '/update.css'); - return $output; } /** @@ -296,7 +335,6 @@ function theme_update_report($variables) { * - status: The integer code for a project's current update status. * * @see update_calculate_project_data() - * @ingroup themeable */ function template_preprocess_update_status_label(&$variables) { $variables['attributes'] = new Attribute(array('class' => array())); @@ -337,13 +375,18 @@ function template_preprocess_update_status_label(&$variables) { * - date: The date of the release. * - download_link: The URL for the downloadable file. * - tag: The title of the project. -*/ + * - class: A array containing extra classes for the wrapping table. + */ function template_preprocess_update_version(&$variables) { $version = $variables['version']; - // Add version to the classes. - $variables['attributes']['class'][] = 'version'; - // Convert the attributes array to an Attribute object. - $variables['attributes'] = new Attribute($variables['attributes']); + + // Remove 'update_version' from the attributes array. This is added through + // template_preprocess() but we do not need it. + // @todo Remove after http://drupal.org/node/1938430 is resolved. + $attributes = array(); + $attributes['class'] = $variables['class']; + $attributes['class'][] = 'version'; + $variables['attributes'] = new Attribute($attributes); $variables['version_link'] = l($version['version'], $version['release_link']); $variables['version_date'] = format_date($version['date'], 'custom', 'Y-M-d');