Bug 20181: (QA follow-up) Remove double check
[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
53     my $p = Koha::Plugins->new();
54
55     return q{} unless $p;
56
57     my @plugins = $p->GetPlugins(
58         {
59             method => 'opac_head',
60         }
61     );
62
63     my @data = map { $_->opac_head || q{} } @plugins;
64
65     return join( "\n", @data );
66 }
67
68 =head3 get_plugins_opac_js
69
70 [% KohaPlugins.get_plugins_opac_js %]
71
72 This method collects the output of all plugins with an opac_js method
73 to output to the javascript section of at the bottom of opac pages.
74
75 =cut
76
77 sub get_plugins_opac_js {
78     return q{}
79       unless C4::Context->preference('UseKohaPlugins');
80
81     my $p = Koha::Plugins->new();
82
83     return q{} unless $p;
84
85     my @plugins = $p->GetPlugins(
86         {
87             method => 'opac_js',
88         }
89     );
90
91     my @data = map { $_->opac_js || q{} } @plugins;
92
93     return join( "\n", @data );
94 }
95
96 1;