From 9d6f961beaecf07741c2221146ed2c17e9c07594 Mon Sep 17 00:00:00 2001 From: "mkanat%bugzilla.org" <> Date: Thu, 17 Dec 2009 05:27:10 +0000 Subject: Bug 525606: Make the template_before_process hook run whenever a template is loaded (including PROCESS and INCLUDE), not just when $template->process is called. Patch by Max Kanat-Alexander r=dkl, a=mkanat --- Bugzilla/Hook.pm | 47 ++++++++++-------- Bugzilla/Template.pm | 23 ++------- Bugzilla/Template/Context.pm | 104 +++++++++++++++++++++++++++++++++++++++ Bugzilla/Template/Plugin/Hook.pm | 1 + 4 files changed, 135 insertions(+), 40 deletions(-) create mode 100644 Bugzilla/Template/Context.pm (limited to 'Bugzilla') diff --git a/Bugzilla/Hook.pm b/Bugzilla/Hook.pm index 5093db903..44b5c3c58 100644 --- a/Bugzilla/Hook.pm +++ b/Bugzilla/Hook.pm @@ -734,15 +734,25 @@ look at the code for C in L.) =head2 template_before_process +This hook is called any time Bugzilla processes a template file, including +calls to C<< $template->process >>, C statements in templates, +and C statements in templates. It is not called when templates +process a C, only when they process a file. + This hook allows you to define additional variables that will be available to -the template being processed. You probably want to restrict your hook -to operating only if a certain file is being loaded (which is why you -get a C argument below). Otherwise, modifying the C argument -will affect every single template in Bugzilla. +the template being processed, or to modify the variables that are currently +in the template. It works exactly as though you inserted code to modify +template variables at the top of a template. + +You probably want to restrict this hook to operating only if a certain +file is being processed (which is why you get a C argument +below). Otherwise, modifying the C argument will affect every single +template in Bugzilla. -Note that this is only called on the top-level C<< $template->process >> -call. It is not called for C<[% PROCESS %]> or C<[% INCLUDE %]> statements -in templates. +B This hook is not called if you are already in this hook. +(That is, it won't call itself recursively.) This prevents infinite +recursion in situations where this hook needs to process a template +(such as if this hook throws an error). Params: @@ -750,28 +760,25 @@ Params: =item C -The template vars hashref--these are the values that get passed to the -template. Adding new keys to this hashref will cause those new values -to also get passed to the template. +This is the entire set of variables that the current template can see. +Technically, this is a L object, but you can just +use it like a hashref if you want. -=item C +=item C -The name of the template being processed. This is relative -to the main template directory for the language (i.e. for +The name of the template file being processed. This is relative to the +main template directory for the language (i.e. for F