diff options
-rw-r--r-- | Bugzilla/Hook.pm | 15 | ||||
-rw-r--r-- | Bugzilla/Template.pm | 1 | ||||
-rw-r--r-- | extensions/Example/Extension.pm | 13 |
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) = @_; |