summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeter Philipp2012-04-26 00:39:42 (GMT)
committer Peter Philipp2012-04-26 00:39:42 (GMT)
commit262d9aa86bb99ef80559e16b4997a002341731b1 (patch)
tree2221ee9193ac682778c193c4a83f0d636b64b918
parent59461eb743a42205bbf217b9a3cf6a665081b04f (diff)
Catch edge cases where the display title isn't translated yet.
-rw-r--r--i18n_panels.module36
1 files changed, 31 insertions, 5 deletions
diff --git a/i18n_panels.module b/i18n_panels.module
index eba5ece..bfd933c 100644
--- a/i18n_panels.module
+++ b/i18n_panels.module
@@ -200,18 +200,44 @@ function i18n_panels_panels_delete_display($did) {
/**
* Implements hook_panels_pre_render().
*
+ * This function must not rely on the passed $renderer parameter. The parameter
+ * could be empty because this function is reused in i18n_ctools_render_alter().
+ * @todo Check if a drupal_alter() in panels_display::get_title() is applicable.
+ *
+ * @see i18n_ctools_render_alter()
+ *
* @param panels_display $display
* The display to deal with.
* @param panels_renderer_standard $renderer
* The renderer to deal with.
*/
function i18n_panels_panels_pre_render(&$display, $renderer) {
- $translation = i18n_string_object_translate('display_configuration', $display);
- if (is_array($translation->title)) {
- $display->title = $translation->title['string'];
+ // Avoid double translations.
+ if (!isset($display->i18n_panels_title_translated)) {
+ $translation = i18n_string_object_translate('display_configuration', $display);
+ if (is_array($translation->title)) {
+ $display->title = $translation->title['string'];
+ }
+ else {
+ $display->title = $translation->title;
+ }
+ $display->i18n_panels_title_translated = TRUE;
}
- else {
- $display->title = $translation->title;
+}
+
+/**
+ * Implements hook_ctools_render_alter().
+ *
+ * Under some circumstances the title of the panel page is set before
+ * hook_panels_pre_render() is fired. Such cases can be handled with this hook.
+ * @todo Check if a drupal_alter() in panels_display::get_title() is applicable.
+ */
+function i18n_ctools_render_alter(&$info, $page, $context) {
+ // @todo Find a better way to detect a panels page.
+ if ($page === TRUE && !empty($info['content']['#display']) && $info['content']['#display'] instanceof panels_display) {
+ i18n_panels_panels_pre_render($info['content']['#display'], NULL);
+ // Set the info title. This is used to set the page title.
+ $info['title'] = $info['content']['#display']->get_title();
}
}