From 78be753e3be38903b0eeb81e36a7c51704bc6cf3 Mon Sep 17 00:00:00 2001 From: Max Kanat-Alexander Date: Sun, 28 Feb 2010 17:33:29 -0800 Subject: Bug 508823: Make it so that you don't ever have to reset template_inner (like Bugzilla->template_inner("")). r=LpSolit, a=LpSolit --- Bugzilla/Template.pm | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'Bugzilla/Template.pm') diff --git a/Bugzilla/Template.pm b/Bugzilla/Template.pm index 44282e4bc..79382ece2 100644 --- a/Bugzilla/Template.pm +++ b/Bugzilla/Template.pm @@ -84,9 +84,9 @@ sub _load_constants { # settings of the user and of the available languages # If no Accept-Language is present it uses the defined default # Templates may also be found in the extensions/ tree -sub getTemplateIncludePath { +sub _include_path { + my $lang = shift || ''; my $cache = Bugzilla->request_cache; - my $lang = $cache->{'language'} || ''; $cache->{"template_include_path_$lang"} ||= template_include_path({ language => $lang }); return $cache->{"template_include_path_$lang"}; @@ -428,6 +428,17 @@ $Template::Stash::SCALAR_OPS->{ truncate } = ############################################################################### +sub process { + my $self = shift; + # All of this current_langs stuff allows template_inner to correctly + # determine what-language Template object it should instantiate. + my $current_langs = Bugzilla->request_cache->{template_current_lang} ||= []; + unshift(@$current_langs, $self->context->{bz_language}); + my $retval = $self->SUPER::process(@_); + shift @$current_langs; + return $retval; +} + # Construct the Template object # Note that all of the failure cases here can't use templateable errors, @@ -442,7 +453,8 @@ sub create { my $config = { # Colon-separated list of directories containing templates. - INCLUDE_PATH => $opts{'include_path'} || getTemplateIncludePath(), + INCLUDE_PATH => $opts{'include_path'} + || _include_path($opts{'language'}), # Remove white-space before template directives (PRE_CHOMP) and at the # beginning and end of templates and template blocks (TRIM) for better @@ -787,6 +799,11 @@ sub create { Bugzilla::Hook::process('template_before_create', { config => $config }); my $template = $class->new($config) || die("Template creation failed: " . $class->error()); + + # Pass on our current language to any template hooks or inner templates + # called by this Template object. + $template->context->{bz_language} = $opts{language} || ''; + return $template; } -- cgit v1.2.3-24-g4f1b