Issue #1898428 by joelpittet, shanethehat, Floydm, gillbates, steinmb, artis, Cottser, gnuget: locale.module - Convert theme_ functions to Twig.

8.0.x
Alex Pott 2013-06-17 01:54:01 +02:00
parent bd6ad51a89
commit 42c1a7c014
4 changed files with 95 additions and 30 deletions

View File

@ -259,10 +259,12 @@ function locale_theme() {
'locale_translation_last_check' => array( 'locale_translation_last_check' => array(
'variables' => array('last' => NULL), 'variables' => array('last' => NULL),
'file' => 'locale.pages.inc', 'file' => 'locale.pages.inc',
'template' => 'locale-translation-last-check',
), ),
'locale_translation_update_info' => array( 'locale_translation_update_info' => array(
'arguments' => array('updates' => array(), 'not_found' => array()), 'arguments' => array('updates' => array(), 'not_found' => array()),
'file' => 'locale.pages.inc', 'file' => 'locale.pages.inc',
'template' => 'locale-translation-update-info',
), ),
); );
} }

View File

@ -546,7 +546,8 @@ function locale_translation_status_form($form, &$form_state) {
$last_checked = Drupal::state()->get('locale.translation_last_checked'); $last_checked = Drupal::state()->get('locale.translation_last_checked');
$form['last_checked'] = array( $form['last_checked'] = array(
'#markup' => '<p>' . theme('locale_translation_last_check', array('last' => $last_checked)) . '</p>', '#theme' => 'locale_translation_last_check',
'#last' => $last_checked,
); );
$header = array( $header = array(
@ -736,7 +737,11 @@ function theme_locale_translate_edit_form_strings($variables) {
} }
/** /**
* Returns HTML for translation status information per language. * Prepares variables for translation status information templates.
*
* Translation status information is displayed per language.
*
* Default template: locale-translate-edit-form-strings.html.twig.
* *
* @param array $variables * @param array $variables
* An associative array containing: * An associative array containing:
@ -744,10 +749,9 @@ function theme_locale_translate_edit_form_strings($variables) {
* - not_found: The projects which updates are not found. * - not_found: The projects which updates are not found.
* *
* @see locale_translation_status_form() * @see locale_translation_status_form()
* @ingroup themeable
*/ */
function theme_locale_translation_update_info($variables) { function template_preprocess_locale_translation_update_info(&$variables) {
$description = $details = ''; $details = array();
// Build output for available updates. // Build output for available updates.
if (isset($variables['updates'])) { if (isset($variables['updates'])) {
@ -757,16 +761,17 @@ function theme_locale_translation_update_info($variables) {
$modules[] = $update['name']; $modules[] = $update['name'];
$releases[] = t('@module (@date)', array('@module' => $update['name'], '@date' => format_date($update['timestamp'], 'html_date'))); $releases[] = t('@module (@date)', array('@module' => $update['name'], '@date' => format_date($update['timestamp'], 'html_date')));
} }
$variables['modules'] = $modules;
} }
$description = '<span class="text">' . t('Updates for: @modules', array('@modules' => implode(', ', $modules))) . '</span>'; $details['available_updates_list'] = array(
$details = theme('item_list', array('items' => $releases)); '#theme' => 'item_list',
'#items' => $releases,
);
} }
// Build output for updates not found. // Build output for updates not found.
if (isset($variables['not_found'])) { if (isset($variables['not_found'])) {
if (empty($description)) { $variables['missing_updates_status'] = format_plural(count($variables['not_found']), 'Missing translations for one project', 'Missing translations for @count projects');
$description = '<span class="text">' . format_plural(count($variables['not_found']), 'Missing translations for one project', 'Missing translations for @count projects') . '</span>';
}
if ($variables['not_found']) { if ($variables['not_found']) {
$releases = array(); $releases = array();
foreach ($variables['not_found'] as $update) { foreach ($variables['not_found'] as $update) {
@ -774,38 +779,38 @@ function theme_locale_translation_update_info($variables) {
$releases[] = t('@module (@version).', array('@module' => $update['name'], '@version' => $version)) . ' ' . $update['info']; $releases[] = t('@module (@version).', array('@module' => $update['name'], '@version' => $version)) . ' ' . $update['info'];
} }
} }
if ($details) { $details['missing_updates_list'] = array(
$details .= t('Missing translations for:'); '#theme' => 'item_list',
'#items' => $releases,
);
// Prefix the missing updates list if there is an available updates lists
// before it.
if (!empty($details['available_updates_list']['#items'])) {
$details['missing_updates_list']['#prefix'] = t('Missing translations for:');
} }
$details .= theme('item_list', array('items' => $releases));
} }
$variables['details'] = $details;
$output = '<div class="inner" tabindex="0" role="button">';
$output .= '<span class="update-description-prefix element-invisible">Show description</span>' . $description;
$output .= $details ? '<div class="details">' . $details . '</div>' : '';
$output .= '</div>';
return $output;
} }
/** /**
* Returns HTML for the last time we checked for update data. * Prepares variables for most recent translation update templates.
* *
* In addition to properly formatting the given timestamp, this function also * Displays the last time we checked for locale update data. In addition to
* provides a "Check manually" link that refreshes the available update and * properly formatting the given timestamp, this function also provides a "Check
* redirects back to the same page. * manually" link that refreshes the available update and redirects back to the
* same page.
*
* Default template: locale-translation-last-check.html.twig.
* *
* @param $variables * @param $variables
* An associative array containing: * An associative array containing:
* - last: The timestamp when the site last checked for available updates. * - last: The timestamp when the site last checked for available updates.
* *
* @see locale_translation_status_form() * @see locale_translation_status_form()
* @ingroup themeable
*/ */
function theme_locale_translation_last_check($variables) { function template_preprocess_locale_translation_last_check(&$variables) {
$last = $variables['last']; $last = $variables['last'];
$output = '<div class="locale checked">'; $variables['last_checked'] = ($last != NULL);
$output .= $last ? t('Last checked: @time ago', array('@time' => format_interval(REQUEST_TIME - $last))) : t('Last checked: never'); $variables['time'] = format_interval(REQUEST_TIME - $last);
$output .= ' <span class="check-manually">(' . l(t('Check manually'), 'admin/reports/translations/check', array('query' => drupal_get_destination())) . ')</span>'; $variables['link'] = l(t('Check manually'), 'admin/reports/translations/check', array('query' => drupal_get_destination()));
$output .= "</div>\n";
return $output;
} }

View File

@ -0,0 +1,26 @@
{#
/**
* @file
* Default theme implementation for the last time we checked for update data.
*
* Available variables:
* - last_checked: Whether or not locale updates have been checked before.
* - time: The formatted time ago when the site last checked for available
* updates.
* - link: A link to manually check available updates.
*
* @see template_preprocess()
* @see template_preprocess_locale_translation_last_check()
*
* @ingroup themeable
*/
#}
<div class="locale checked">
<p>
{% if last_checked %}
{{ 'Last checked: @time ago'|t({'@time': time}) }}
{% else %}
{{ 'Last checked: never'|t }}
{% endif %}
<span class="check-manually">({{ link }})</span></p>
</div>

View File

@ -0,0 +1,32 @@
{#
/**
* @file
* Default theme implementation for displaying translation status information.
*
* Displays translation status information per language.
*
* Available variables:
* - modules: A list of names of modules that have available translation
* updates.
* - details: Rendered list of the translation details.
* - missing_updates_status: If there are any modules that are missing
* translation updates, this variable will contain text indicating how many
* modules are missing translations.
*
* @see template_preprocess()
* @see template_preprocess_locale_translation_update_info()
*
* @ingroup themeable
*/
#}
<div class="inner" tabindex="0" role="button">
<span class="update-description-prefix element-invisible">Show description</span>
{% if modules %}
<span class="text">{{ 'Updates for: @modules'|t({'@modules': modules|join(', ')}) }}</span>
{% elseif missing_updates_status %}
<span class="text">{{ missing_updates_status }}</span>
{% endif %}
{% if details %}
<div class="details">{{ details }}</div>
{% endif %}
</div>