aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDylan William Hardison <dylan@hardison.net>2018-03-20 22:06:11 -0400
committerJeff Fearn <Jeff.Fearn@gmail.com>2018-03-21 12:06:11 +1000
commitd7cf1c91949248222806f5a32f485b12eab8806f (patch)
tree9e52745afcaa3ec7e995181d0f65ed5abe54c546
parentbug 1429243 - Fix default values for version and op_sys when importing from J... (diff)
downloadbugzilla-d7cf1c91949248222806f5a32f485b12eab8806f.tar.gz
bugzilla-d7cf1c91949248222806f5a32f485b12eab8806f.tar.bz2
bugzilla-d7cf1c91949248222806f5a32f485b12eab8806f.zip
add a new hook: template_after_create (#60)
-rw-r--r--Bugzilla/Hook.pm15
-rw-r--r--Bugzilla/Template.pm1
-rw-r--r--extensions/Example/Extension.pm13
3 files changed, 29 insertions, 0 deletions
diff --git a/Bugzilla/Hook.pm b/Bugzilla/Hook.pm
index d6ba5e1d0..d8ae67463 100644
--- a/Bugzilla/Hook.pm
+++ b/Bugzilla/Hook.pm
@@ -1479,6 +1479,21 @@ look at the code for C<create> in L<Bugzilla::Template>.)
=back
+=head2 template_after_create
+
+This hook allows you to manipulate the Template object before it is used.
+You can use this to define new vmethods or filters in extensions.
+
+Params:
+
+=over
+
+=item C<template>
+
+This is the L<Bugzilla::Template> object.
+
+=back
+
=head2 template_before_process
This hook is called any time Bugzilla processes a template file, including
diff --git a/Bugzilla/Template.pm b/Bugzilla/Template.pm
index decffe1e8..7294e27c1 100644
--- a/Bugzilla/Template.pm
+++ b/Bugzilla/Template.pm
@@ -1186,6 +1186,7 @@ sub create {
Bugzilla::Hook::process('template_before_create', { config => $config });
my $template = $class->new($config)
|| die("Template creation failed: " . $class->error());
+ Bugzilla::Hook::process('template_after_create', { template => $template });
# Pass on our current language to any template hooks or inner templates
# called by this Template object.
diff --git a/extensions/Example/Extension.pm b/extensions/Example/Extension.pm
index dbc84df72..c4fabe656 100644
--- a/extensions/Example/Extension.pm
+++ b/extensions/Example/Extension.pm
@@ -920,6 +920,19 @@ sub template_before_create {
$config->{VARIABLES}->{example_global_variable} = sub { return 'value' };
}
+sub template_after_create {
+ my ( $self, $args ) = @_;
+ my $context = $args->{template}->context;
+
+ # define a pluck method on template toolkit lists.
+ $context->define_vmethod(
+ list => pluck => sub {
+ my ( $list, $field ) = @_;
+ return [ map { $_->$field } @$list ];
+ }
+ );
+}
+
sub template_before_process {
my ($self, $args) = @_;