Bug 508199: A hook for page.cgi
Patch by Max Kanat-Alexander <mkanat@bugzilla.org> r=dkl, a=mkanat git-svn-id: svn://10.0.0.236/branches/BUGZILLA-3_4-BRANCH@257962 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
parent
5d0e212140
commit
a5c9551ef1
@ -478,6 +478,33 @@ Params:
|
||||
|
||||
=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
|
||||
|
||||
Called before displaying the confirmation message when deleting a product.
|
||||
|
||||
@ -0,0 +1,33 @@
|
||||
# -*- 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 };
|
||||
}
|
||||
@ -0,0 +1,32 @@
|
||||
[%#
|
||||
# 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);
|
||||
|
||||
use Bugzilla;
|
||||
use Bugzilla::Error;
|
||||
use Bugzilla::Hook;
|
||||
|
||||
Bugzilla->login();
|
||||
|
||||
@ -50,13 +51,17 @@ if ($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);
|
||||
|
||||
$cgi->param('id', $id);
|
||||
|
||||
print $cgi->header($format->{'ctype'});
|
||||
|
||||
$template->process("$format->{'template'}")
|
||||
$template->process("$format->{'template'}", \%vars)
|
||||
|| ThrowTemplateError($template->error());
|
||||
}
|
||||
else {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user