Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
bugzilla
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
etersoft
bugzilla
Commits
79584710
Commit
79584710
authored
Apr 04, 2008
by
jocuri%softhome.net
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Patch for bug 298341: Implement code hook mechanism; patch by…
Patch for bug 298341: Implement code hook mechanism; patch by zach@zachlipton.com, r=timeless, a=justdave.
parent
88bc5972
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
111 additions
and
90 deletions
+111
-90
customization.xml
docs/en/xml/customization.xml
+111
-90
No files found.
docs/en/xml/customization.xml
View file @
79584710
...
@@ -411,11 +411,11 @@
...
@@ -411,11 +411,11 @@
</section>
</section>
<section
id=
"cust-hooks"
>
<section
id=
"cust-hooks"
>
<title>
T
emplate Hooks
</title>
<title>
T
he Bugzilla Extension Mechanism
</title>
<warning>
<warning>
<para>
<para>
Template Hook
s require Template Toolkit version 2.12 or
Custom extension
s require Template Toolkit version 2.12 or
above, or the application of a patch. See
<ulink
above, or the application of a patch. See
<ulink
url=
"http://bugzilla.mozilla.org/show_bug.cgi?id=239112"
>
bug
url=
"http://bugzilla.mozilla.org/show_bug.cgi?id=239112"
>
bug
239112
</ulink>
for details.
239112
</ulink>
for details.
...
@@ -423,62 +423,82 @@
...
@@ -423,62 +423,82 @@
</warning>
</warning>
<para>
<para>
Template hooks are a way for extensions to Bugzilla to insert code
Extensions are a way for extensions to Bugzilla to insert code
into the standard Bugzilla templates without modifying the template files
into the standard Bugzilla templates and source files
themselves. The hooks mechanism defines a consistent API for extending
without modifying these files themselves. The extension mechanism
the standard templates in a way that cleanly separates standard code
defines a consistent API for extending the standard templates and source files
from extension code. Hooks reduce merge conflicts and make it easier
in a way that cleanly separates standard code from extension code.
to write extensions that work across multiple versions of Bugzilla,
Hooks reduce merge conflicts and make it easier to write extensions that work
making upgrading a Bugzilla installation with installed extensions easier.
across multiple versions of Bugzilla, making upgrading a Bugzilla installation
with installed extensions easier. Furthermore, they make it easy to install
and remove extensions as each extension is nothing more than a
simple directory structure.
</para>
<para>
There are two main types of hooks: code hooks and template hooks. Code
hooks allow extensions to invoke code at specific points in various
source files, while template hooks allow extensions to add elements to
the Bugzilla user interface.
</para>
</para>
<para>
<para>
A template hook is just a named place in a standard template file
A hook is just a named place in a standard source or template file
where extension template files for that hook get processed. Each hook
where extension source code or template files for that hook get processed.
has a corresponding directory in the Bugzilla directory tree. Hooking an
Each extension has a corresponding directory in the Bugzilla directory
extension template to a hook is as simple as putting the extension file
tree (
<filename>
BUGZILLA_ROOT/extensions/extension_name
</filename>
). Hooking
into the hook's directory. When Bugzilla processes the standard template
an extension source file or template to a hook is as simple as putting
and reaches the hook, it will process all extension templates in the
the extension file into extension's template or code directory.
hook's directory. The hooks themselves can be added into any standard
When Bugzilla processes the source file or template and reaches the hook,
template upon request by extension authors.
it will process all extension files in the hook's directory.
The hooks themselves can be added into any source file or standard template
upon request by extension authors.
</para>
</para>
<para>
<para>
To use hooks to extend a Bugzilla template, first make sure there is
To use hooks to extend Bugzilla, first make sure there is
a hook at the appropriate place within the template you want to extend.
a hook at the appropriate place within the source file or template you
Hooks appear in the standard Bugzilla templates as a single directive
want to extend. The exact appearence of a hook depends on if the hook
in the format
is a code hook or a template hook.
<literal
role=
"code"
>
[% Hook.process("
<varname>
name
</varname>
") %]
</literal>
,
where
<varname>
name
</varname>
is the unique (within that template)
name of the hook.
</para>
</para>
<para>
<para>
If you aren't sure which template you want to extend or just want
Code hooks appear in Bugzilla source files as a single method call
to browse the available hooks, either use your favorite multi-file search
in the format
<literal
role=
"code"
>
Bugzilla::Hook->process("
<varname>
name
</varname>
");
</literal>
.
tool (e.g.
<command>
grep
</command>
) to search the standard templates
for instance,
<filename>
enter_bug.cgi
</filename>
may invoke the hook
for occurrences of
<methodname>
Hook.process
</methodname>
or browse
"
<varname>
enter_bug-defaultvars
</varname>
". Thus, a source file at
the directory tree in
<filename>
BUGZILLA_ROOT/extensions/EXTENSION_NAME/code/enter_bug-entrydefaultvars.pl
</filename>
<filename>
BUGZILLA_ROOT/template/en/extension/hook/
</filename>
,
will be automatically invoked when when the code hook is reached.
which contains a directory for each hook in the following location:
<para>
<para>
Template hooks appear in the standard Bugzilla templates as a
single directive in the format
<literal
role=
"code"
>
[% Hook.process("
<varname>
name
</varname>
") %]
</literal>
,
where
<varname>
name
</varname>
is the unique name of the hook.
</para>
</para>
<para>
<para>
<filename>
BUGZILLA_ROOT/template/en/extension/hook/PATH_TO_STANDARD_TEMPLATE/STANDARD_TEMPLATE_NAME/HOOK_NAME/
</filename>
If you aren't sure what you want to extend or just want to browse the
available hooks, either use your favorite multi-file search
tool (e.g.
<command>
grep
</command>
) to search the standard templates
for occurrences of
<methodname>
Hook.process
</methodname>
or the source
files for occurences of
<methodname>
Bugzilla::Hook::process
</methodname>
.
</para>
</para>
<para>
<para>
If there is no hook at the appropriate place within the Bugzilla
template
If there is no hook at the appropriate place within the Bugzilla
you want to extend,
source file or template
you want to extend,
<ulink
url=
"http://bugzilla.mozilla.org/enter_bug.cgi?product=Bugzilla&component=User%20Interface"
>
file
<ulink
url=
"http://bugzilla.mozilla.org/enter_bug.cgi?product=Bugzilla&component=User%20Interface"
>
file
a bug requesting one
</ulink>
, specifying:
a bug requesting one
</ulink>
, specifying:
</para>
</para>
<simplelist>
<simplelist>
<member>
the template for which you are requesting a hook;
</member>
<member>
the source or template file for which you are
requesting a hook;
</member>
<member>
<member>
where in the
templat
e you would like the hook to be placed
where in the
fil
e you would like the hook to be placed
(line number/position for latest version of t
emplat
e in CVS
(line number/position for latest version of t
he fil
e in CVS
or description of location);
or description of location);
</member>
</member>
<member>
the purpose of the hook;
</member>
<member>
the purpose of the hook;
</member>
...
@@ -487,9 +507,8 @@
...
@@ -487,9 +507,8 @@
<para>
<para>
The Bugzilla reviewers will promptly review each hook request,
The Bugzilla reviewers will promptly review each hook request,
name the hook, add it to the template, check the new version
name the hook, add it to the template or source file, and check
of the template into CVS, and create the corresponding directory in
the new version of the template into CVS.
<filename>
BUGZILLA_ROOT/template/en/extension/hook/
</filename>
.
</para>
</para>
<para>
<para>
...
@@ -505,13 +524,13 @@
...
@@ -505,13 +524,13 @@
<para>
<para>
After making sure the hook you need exists (or getting it added if not),
After making sure the hook you need exists (or getting it added if not),
add your extension t
emplate t
o the directory within the Bugzilla
add your extension to the directory within the Bugzilla
directory
tree corresponding to the hook.
extensions
tree corresponding to the hook.
</para>
</para>
<para>
<para>
That's it! Now, when the s
tandard
template containing the hook
That's it! Now, when the s
ource file or
template containing the hook
is processed, your extension
templat
e will be processed at the point
is processed, your extension
fil
e will be processed at the point
where the hook appears.
where the hook appears.
</para>
</para>
...
@@ -542,14 +561,9 @@
...
@@ -542,14 +561,9 @@
...]]>
</programlisting>
...]]>
</programlisting>
<para>
<para>
The corresponding directory for this hook is
The corresponding extension file for this hook is
<filename>
BUGZILLA_ROOT/template/en/extension/hook/global/useful-links.html.tmpl/edit/
</filename>
.
<filename>
BUGZILLA_ROOT/extensions/projman/template/en/hook/global/useful-links-edit.html.tmpl
</filename>
.
</para>
You then create that template file and add the following constant:
<para>
You put a template named
<filename>
projman-edit-projects.html.tmpl
</filename>
into that directory with the following content:
</para>
</para>
<programlisting>
<![CDATA[...[% ', <a href="edit-projects.cgi">projects</a>' IF user.groups.projman_admins %]]]>
</programlisting>
<programlisting>
<![CDATA[...[% ', <a href="edit-projects.cgi">projects</a>' IF user.groups.projman_admins %]]]>
</programlisting>
...
@@ -558,7 +572,28 @@
...
@@ -558,7 +572,28 @@
Voila! The link now appears after the other administration links in the
Voila! The link now appears after the other administration links in the
navigation bar for users in the
<literal>
projman_admins
</literal>
group.
navigation bar for users in the
<literal>
projman_admins
</literal>
group.
</para>
</para>
<para>
Now, let us say your extension adds a custom "project_manager" field
to enter_bug.cgi. You want to modify the CGI script to set the default
project manager to be productname@company.com. Looking at
<filename>
enter_bug.cgi
</filename>
, you see the enter_bug-entrydefaultvars
hook near the bottom of the file before the default form values are set.
The corresponding extension source file for this hook is located at
<filename>
BUGZILLA_ROOT/extensions/projman/code/enter_bug-entrydefaultvars.pl
</filename>
.
You then create that file and add the following:
</para>
<programlisting>
$default{'project_manager'} = $product.'@company.com';
</programlisting>
<para>
This code will be invoked whenever enter_bug.cgi is executed.
Assuming that the rest of the customization was completed (e.g. the
custom field was added to the enter_bug template and the required hooks
were used in process_bug.cgi), the new field will now have this
default value.
</para>
<para>
<para>
Notes:
Notes:
</para>
</para>
...
@@ -566,61 +601,47 @@
...
@@ -566,61 +601,47 @@
<itemizedlist>
<itemizedlist>
<listitem>
<listitem>
<para>
<para>
You may want to prefix your extension template names
with the name of your extension, e.g.
<filename>
projman-foo.html.tmpl
</filename>
,
so they do not conflict with the names of templates installed by
other extensions.
</para>
</listitem>
<listitem>
<para>
If your extension includes entirely new templates in addition to
If your extension includes entirely new templates in addition to
extensions of standard templates, it should
install
those new
extensions of standard templates, it should
store
those new
templates in
to an extension-specific subdirectory of the
templates in
its
<filename>
BUGZILLA_ROOT/
template/en/extensio
n/
</filename>
<filename>
BUGZILLA_ROOT/
extensions/template/e
n/
</filename>
directory.
The
<filename>
extension/
</filename>
directory
, like the
directory.
Extension template directories
, like the
<filename>
default/
</filename>
and
<filename>
custom/
</filename>
<filename>
default/
</filename>
and
<filename>
custom/
</filename>
directories,
is
part of the template search path, so putting templates
directories,
are
part of the template search path, so putting templates
there enables them to be found by the template processor.
there enables them to be found by the template processor.
</para>
</para>
<para>
<para>
The template processor looks for templates first in the
The template processor looks for templates first in the
<filename>
custom/
</filename>
directory (i.e. templates added by the
<filename>
custom/
</filename>
directory (i.e. templates added by the
specific installation), then in the
<filename>
extension
/
</filename>
specific installation), then in the
<filename>
extension
s/
</filename>
directory (i.e. templates added by extensions), and finally in the
directory (i.e. templates added by extensions), and finally in the
<filename>
default/
</filename>
directory (i.e. the standard Bugzilla
<filename>
default/
</filename>
directory (i.e. the standard Bugzilla
templates). Thus extension templates can override standard templates,
templates). Thus, installation-specific templates override both
but installation-specific templates override both.
default and extension templates.
</para>
<para>
Note that overriding standard templates with extension templates
gives you great power but also makes upgrading an installation harder.
As with custom templates, we recommend using this functionality
sparingly and only when absolutely necessary.
</para>
</para>
</listitem>
</listitem>
<listitem>
<listitem>
<para>
<para>
I
nstallation customizers can also take advantage of hooks when adding
I
f you are looking to customize Bugzilla, you can also take advantage
code to a Bugzilla template. To do so, create directories
in
of template hooks. To do so, create a directory
in
<filename>
BUGZILLA_ROOT/template/en/custom/hook/
</filename>
<filename>
BUGZILLA_ROOT/template/en/custom/hook/
</filename>
equivalent to the directories in
that corresponds to the hook you wish to use, then place your
<filename>
BUGZILLA_ROOT/template/en/extension/hook/
</filename>
customization templates into those directories. For example,
for the hooks you want to use, then place your customization templates
if you wanted to use the hook "end" in
into those directories.
<filename>
global/useful-links.html.tmpl
</filename>
, you would
create the directory
<filename>
BUGZILLA_ROOT/template/en/custom/hook/
global/useful-links.html.tmpl/end/
</filename>
and add your customization
template to this directory.
</para>
</para>
<para>
<para>
Obviously this method of customizing Bugzilla only lets you add code
Obviously this method of customizing Bugzilla only lets you add code
to the standard
templates; you cannot change the existing code.
to the standard
source files and templates; you cannot change the
Nevertheless, for those customizations that only add code, this method
existing code. Nevertheless, for those customizations that only add
c
an reduce conflicts when merging changes, making upgrading
c
ode, this method can reduce conflicts when merging changes,
your customized Bugzilla installation easier.
making upgrading
your customized Bugzilla installation easier.
</para>
</para>
</listitem>
</listitem>
</itemizedlist>
</itemizedlist>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment