Commit 360c7807 authored by mkanat%bugzilla.org's avatar mkanat%bugzilla.org

Bug 508199: A hook for page.cgi

Patch by Max Kanat-Alexander <mkanat@bugzilla.org> r=dkl, a=mkanat
parent c0486757
...@@ -478,6 +478,33 @@ Params: ...@@ -478,6 +478,33 @@ Params:
=back =back
=head2 page-before_template
This is a simple way to add your own pages to Bugzilla. This hooks C<page.cgi>,
which loads templates from F<template/en/default/pages>. For example,
C<page.cgi?id=fields.html> loads F<template/en/default/pages/fields.html.tmpl>.
This hook is called right before the template is loaded, so that you can
pass your own variables to your own pages.
Params:
=over
=item C<page_id>
This is the name of the page being loaded, like C<fields.html>.
Note that if two extensions use the same name, it is uncertain which will
override the others, so you should be careful with how you name your pages.
=item C<vars>
This is a hashref--put variables into here if you want them passed to
your template.
=back
=head2 product-confirm_delete =head2 product-confirm_delete
Called before displaying the confirmation message when deleting a product. Called before displaying the confirmation message when deleting a product.
......
# -*- Mode: perl; indent-tabs-mode: nil -*-
#
# The contents of this file are subject to the Mozilla Public
# License Version 1.1 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of
# the License at http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
# implied. See the License for the specific language governing
# rights and limitations under the License.
#
# The Original Code is the Bugzilla Example Plugin.
#
# The Initial Developer of the Original Code is Canonical Ltd.
# Portions created by Canonical Ltd. are Copyright (C) 2009
# Canonical Ltd. All Rights Reserved.
#
# Contributor(s):
# Max Kanat-Alexander <mkanat@bugzilla.org>
use strict;
use warnings;
use Bugzilla;
my %args = %{ Bugzilla->hook_args };
my ($vars, $page) = @args{qw(vars page_id)};
# You can see this hook in action by loading page.cgi?id=example.html
if ($page eq 'example.html') {
$vars->{cgi_variables} = { Bugzilla->cgi->Vars };
}
[%#
# The contents of this file are subject to the Mozilla Public
# License Version 1.1 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of
# the License at http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
# implied. See the License for the specific language governing
# rights and limitations under the License.
#
# The Original Code is the Bugzilla Example Plugin.
#
# The Initial Developer of the Original Code is Canonical Ltd.
# Portions created by Canonical Ltd. are Copyright (C) 2009
# Canonical Ltd. All Rights Reserved.
#
# Contributor(s):
# Max Kanat-Alexander <mkanat@bugzilla.org>
#%]
[% PROCESS global/header.html.tmpl
title = "Example Page"
%]
<p>Here's what you passed me:</p>
[% USE Dumper %]
<pre>
[% Dumper.dump_html(cgi_variables) %]
</pre>
[% PROCESS global/footer.html.tmpl %]
...@@ -34,6 +34,7 @@ use lib qw(. lib); ...@@ -34,6 +34,7 @@ use lib qw(. lib);
use Bugzilla; use Bugzilla;
use Bugzilla::Error; use Bugzilla::Error;
use Bugzilla::Hook;
Bugzilla->login(); Bugzilla->login();
...@@ -50,13 +51,17 @@ if ($id) { ...@@ -50,13 +51,17 @@ if ($id) {
ThrowCodeError("bad_page_cgi_id", { "page_id" => $id }); ThrowCodeError("bad_page_cgi_id", { "page_id" => $id });
} }
my %vars;
Bugzilla::Hook::process('page-before_template',
{ page_id => $id, vars => \%vars });
my $format = $template->get_format("pages/$1", undef, $2); my $format = $template->get_format("pages/$1", undef, $2);
$cgi->param('id', $id); $cgi->param('id', $id);
print $cgi->header($format->{'ctype'}); print $cgi->header($format->{'ctype'});
$template->process("$format->{'template'}") $template->process("$format->{'template'}", \%vars)
|| ThrowTemplateError($template->error()); || ThrowTemplateError($template->error());
} }
else { else {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment