Closed Bug 394438 Opened 18 years ago Closed 16 years ago

Add a hook for adding template vars to any page (Override Template->process)

Categories

(Bugzilla :: Creating/Changing Bugs, enhancement)

enhancement
Not set
normal

Tracking

()

RESOLVED FIXED
Bugzilla 3.6

People

(Reporter: jesper, Assigned: mattr)

References

Details

Attachments

(1 file, 7 obsolete files)

User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6 Build Identifier: Bugzilla 3.0.1 Is it possible to add a new hook in the show_bug.cgi: 33d32 < use Bugzilla::Hook; 140,141d138 < Bugzilla::Hook::process("show_bug-entrydefaultvars", { vars => $vars }); < Reproducible: Always Steps to Reproduce: 1. 2. 3.
Describe why you want it and attach a patch as a unified diff. See the Contributor Guidelines here: http://wiki.mozilla.org/Bugzilla:Developers
OS: Linux → All
Hardware: PC → All
This patch implements the specified hook, although it gives it a different name. I want it so that I can access variables from a template hook that I've added to bug/edit.html.tmpl (which I will also be submitting) Should I update the POD documentation for the additional hook as well?
Instead of this, why don't you just hook template->process and add things to the $vars hash based on what template is being processed? And yes, new hooks always need POD and an example.
Add an overload to Bugzilla::Template in order to hook Template->process as suggested. Is this what you were talking about about when you said hook template->process? If so, and the patch is correct, I'll also submit POD and an example in separate patches.
Attachment #389081 - Attachment is obsolete: true
Status: UNCONFIRMED → NEW
Ever confirmed: true
Summary: New Hook in show_bug.cgi → Add a hook for adding template vars to any page (Override Template->process)
Target Milestone: --- → Bugzilla 3.6
Comment on attachment 389250 [details] [diff] [review] add an overload of Template::process with a hook for adding vars >Index: Template.pm >+ my $self = shift; >+ my $vars = $_[1]; >+ >+ Bugzilla::Hook::process("template-addvariables", {'vars' => $vars, >+ 'page' => $_[0]}); Looks great. Just call it template-before_process. Also, call the "page" argument "template". >+ >+ $_[1] = $vars; You don't need to do that, because $vars is a ref to start with, and so will be modified anyway. >+ return $self->{SUPER}::process(@_); Nit: No {} around SUPER. Now this needs POD and an example.
Attachment #389250 - Flags: review-
Second (and hopefully final) version of the actual patch to overload Template::process to add a hook. Should address the earlier comments. POD and example coming in other attachments.
Attachment #389250 - Attachment is obsolete: true
Here is the POD for Bugzilla/Hook.pm to describe the new hook.
This is the example code hook for the new template-before_process hook. It should go to extensions/example/code
Write a single patch with all changes in it, not one patch per file.
Attached patch Full patch (obsolete) — Splinter Review
This is the same as attachments 389317 and 389318, just combined into a single patch. The new example file is left separate since i don't have write access to CVS
Attachment #389317 - Attachment is obsolete: true
Attachment #389318 - Attachment is obsolete: true
This will add overhead for each template, so we need the fixes to stop creating/processing templates multiple times per comment first. Rather than having a fixed hookname, wouldn't it be better to have a 'before_template_process_$template' hook? Would make the hook .pl file cleaner, I think
Depends on: 499151, 498309
(In reply to comment #11) > This will add overhead for each template, so we need the fixes to stop > Rather than having a fixed hookname, wouldn't it be better to have a > 'before_template_process_$template' hook? Would make the hook .pl file cleaner, > I think No, there are hundreds of templates, it would be silly to make a hook for each one. It's better to offer a flexible interface for extension authors.
(In reply to comment #10) > The new example file is left separate since i don't have write access to > CVS You don't need to do that. Look up "cvsdo", or just read the patching guide linked from http://wiki.mozilla.org/Bugzilla:Developers
Full patch with changes based on last bits of feedback
Attachment #389319 - Attachment is obsolete: true
Attachment #389322 - Attachment is obsolete: true
(In reply to comment #12) > No, there are hundreds of templates, it would be silly to make a hook for > each one. It's better to offer a flexible interface for extension authors. Why? Each one is going to be doing something different - separate files is cleaner than a bunch of if statements.
(In reply to comment #15) > Why? Each one is going to be doing something different - separate files is > cleaner than a bunch of if statements. Separate hooks requires us to forever predetermine exactly what files extension authors will want to modify--that just isn't good design, on our part. Cleanliness or lack of cleanliness is the responsibility of the extension author. I can personally think of some very clean ways to implement things for different templates, such as a hash that points to subroutine references.
Comment on attachment 389339 [details] [diff] [review] combined patch to add hooks to template->process Hey Matt--I'm sorry that I never got around to reviewing this! It's because I was never asked for review--our development process is described here: http://wiki.mozilla.org/Bugzilla:Developers Anyhow, this looks fine, and just needs a few adjustments that I can make on checkin (copyright, and some tiny style things, and I might also pass the template object itself to the hook and possibly change some names).
Attachment #389339 - Flags: review+
Assignee: create-and-change → mattr
Status: NEW → ASSIGNED
Checking in Bugzilla/Hook.pm; /cvsroot/mozilla/webtools/bugzilla/Bugzilla/Hook.pm,v <-- Hook.pm new revision: 1.32; previous revision: 1.31 done Checking in Bugzilla/Template.pm; /cvsroot/mozilla/webtools/bugzilla/Bugzilla/Template.pm,v <-- Template.pm new revision: 1.111; previous revision: 1.110 done RCS file: /cvsroot/mozilla/webtools/bugzilla/extensions/example/code/template-before_process.pl,v done Checking in extensions/example/code/template-before_process.pl; /cvsroot/mozilla/webtools/bugzilla/extensions/example/code/template-before_process.pl,v <-- template-before_process.pl initial revision: 1.1 done
Status: ASSIGNED → RESOLVED
Closed: 16 years ago
Flags: approval+
Resolution: --- → FIXED
Attachment #389339 - Attachment is obsolete: true
Attachment #407417 - Flags: review+
Comment on attachment 407417 [details] [diff] [review] Checked-In Version Oh, template-before_process is missing in this patch, but it did get checked in properly.
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: