Bug 20181: Add POD for new plugin
[koha.git] / Koha / Template / Plugin / KohaPlugins.pm
1 package Koha::Template::Plugin::KohaPlugins;
2
3 # This file is part of Koha.
4 #
5 # Copyright ByWater Solutions 2018
6 #
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 3 of the License, or (at your option) any later
10 # version.
11 #
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License along
17 # with Koha; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20 use Modern::Perl;
21
22 use base qw( Template::Plugin );
23
24 use Koha::Plugins;
25
26 =head1 NAME
27
28 Koha::Template::Plugin::KohaPlugins - A module for adding hooks into Koha for plugins
29
30 =head1 DESCRIPTION
31
32 This plugin contains functions related to adding plugin hooks into various parts
33 of Koha.
34
35 To use, include the line '[% USE KohaPlugins %]' at the top of the template
36 to enable the plugin
37
38 =head2 Methods
39
40 =head3 get_plugins_opac_head
41
42 [% KohaPlugins.get_plugins_opac_head %]
43
44 This method collects the output of all plugins with an opac_head method
45 to output to the head section of opac pages.
46
47 =cut
48
49 sub get_plugins_opac_head {
50     return q{}
51       unless C4::Context->preference('UseKohaPlugins')
52       && C4::Context->config("enable_plugins");
53
54     my @plugins = Koha::Plugins->new()->GetPlugins(
55         {
56             method => 'opac_head',
57         }
58     );
59
60     my @data = map { $_->opac_head || q{} } @plugins;
61
62     return join( "\n", @data );
63 }
64
65 =head3 get_plugins_opac_js
66
67 [% KohaPlugins.get_plugins_opac_js %]
68
69 This method collects the output of all plugins with an opac_js method
70 to output to the javascript section of at the bottom of opac pages.
71
72 =cut
73
74 sub get_plugins_opac_js {
75     return q{}
76       unless C4::Context->preference('UseKohaPlugins')
77       && C4::Context->config("enable_plugins");
78
79     my @plugins = Koha::Plugins->new()->GetPlugins(
80         {
81             method => 'opac_js',
82         }
83     );
84
85     my @data = map { $_->opac_js || q{} } @plugins;
86
87     return join( "\n", @data );
88 }
89
90 1;