]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
add a new hook: template_after_create (#60)
authorDylan William Hardison <dylan@hardison.net>
Wed, 21 Mar 2018 02:06:11 +0000 (22:06 -0400)
committerJeff Fearn <Jeff.Fearn@gmail.com>
Wed, 21 Mar 2018 02:06:11 +0000 (12:06 +1000)
Bugzilla/Hook.pm
Bugzilla/Template.pm
extensions/Example/Extension.pm

index d6ba5e1d0e471284489d7b0ca0eac592f0987af9..d8ae674636d448a9b17b35529f2bdfed4cdf3408 100644 (file)
@@ -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
index decffe1e8d5eb4eaeb686f007140b2b048d80f35..7294e27c195e650bc2596cbf4f591627f2fa187e 100644 (file)
@@ -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.
index dbc84df7211ce78ac402d3796afb71e6748065f1..c4fabe656b3620c7356c61e6e1c21e04cf54e257 100644 (file)
@@ -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) = @_;