From a37637e30357258885e9d0c1c7a30366869dcb08 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Sat, 15 Sep 2018 09:48:49 -0700 Subject: [PATCH] Bug 21352: Allow plugins to add CSS and Javascript to Staff interface We should have plugin hooks for the staff interface just like we have for the OPAC as detailed on bug 20181. Test Plan: 1) Apply this patch 2) Download and install the Kitchen Sink plugin ( v2.1.19 or later ) https://github.com/bywatersolutions/koha-plugin-kitchen-sink/releases/download/v2.1.19/koha-plugin-kitchen-sink-v2.1.19.kpz 3) Install the plugin 4) Restart all the things if you can ( restart_all if you are using kohadevbox ) This will ensure the plugin takes effect right away, it should be necessary but it won't hurt anything! 5) Load the staff intranet, notice you get an console error log message and the background for your staff intranet is now orange ( assuming you've not customized the staff intranet in any way ) Signed-off-by: Owen Leonard Signed-off-by: Tomas Cohen Arazi Signed-off-by: Nick Clemens --- Koha/Template/Plugin/KohaPlugins.pm | 56 +++++++++++++++++++ .../prog/en/includes/doc-head-close.inc | 2 + .../prog/en/includes/intranet-bottom.inc | 1 + .../Koha/Template/Plugin/KohaPlugins.t | 6 +- t/db_dependent/Plugins.t | 2 + t/lib/Koha/Plugin/Test.pm | 10 ++++ 6 files changed, 76 insertions(+), 1 deletion(-) diff --git a/Koha/Template/Plugin/KohaPlugins.pm b/Koha/Template/Plugin/KohaPlugins.pm index 0148c7f301..8624504cdb 100644 --- a/Koha/Template/Plugin/KohaPlugins.pm +++ b/Koha/Template/Plugin/KohaPlugins.pm @@ -93,4 +93,60 @@ sub get_plugins_opac_js { return join( "\n", @data ); } +=head3 get_plugins_intranet_head + +[% KohaPlugins.get_plugins_intranet_head %] + +This method collects the output of all plugins with an intranet_head method +to output to the head section of intranet pages. + +=cut + +sub get_plugins_intranet_head { + return q{} + unless C4::Context->preference('UseKohaPlugins'); + + my $p = Koha::Plugins->new(); + + return q{} unless $p; + + my @plugins = $p->GetPlugins( + { + method => 'intranet_head', + } + ); + + my @data = map { $_->intranet_head || q{} } @plugins; + + return join( "\n", @data ); +} + +=head3 get_plugins_intranet_js + +[% KohaPlugins.get_plugins_intranet_js %] + +This method collects the output of all plugins with an intranet_js method +to output to the javascript section of at the bottom of intranet pages. + +=cut + +sub get_plugins_intranet_js { + return q{} + unless C4::Context->preference('UseKohaPlugins'); + + my $p = Koha::Plugins->new(); + + return q{} unless $p; + + my @plugins = $p->GetPlugins( + { + method => 'intranet_js', + } + ); + + my @data = map { $_->intranet_js || q{} } @plugins; + + return join( "\n", @data ); +} + 1; diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/doc-head-close.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/doc-head-close.inc index c8d268015e..0cd6b7ea38 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/doc-head-close.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/doc-head-close.inc @@ -25,6 +25,8 @@ [% END %] [% IF ( IntranetUserCSS ) %][% END %] +[% KohaPlugins.get_plugins_intranet_head | html %] + [% UNLESS ( footerjs ) %] [% INCLUDE js_includes.inc %] [% END %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/intranet-bottom.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/intranet-bottom.inc index 022c4e33a2..cfbf362c7a 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/intranet-bottom.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/intranet-bottom.inc @@ -72,4 +72,5 @@ [% jsinclude | $raw # Parse the page template's JavaScript block if necessary %] [% END %] +[% KohaPlugins.get_plugins_intranet_js | html %] diff --git a/t/db_dependent/Koha/Template/Plugin/KohaPlugins.t b/t/db_dependent/Koha/Template/Plugin/KohaPlugins.t index 7698bf4686..b0d50e66a0 100755 --- a/t/db_dependent/Koha/Template/Plugin/KohaPlugins.t +++ b/t/db_dependent/Koha/Template/Plugin/KohaPlugins.t @@ -2,7 +2,7 @@ use Modern::Perl; -use Test::More tests => 10; +use Test::More tests => 14; use CGI; use File::Basename; use File::Spec; @@ -40,8 +40,12 @@ t::lib::Mocks::mock_preference('UseKohaPlugins',1); t::lib::Mocks::mock_config('enable_plugins',1); ok( index( $plugin->get_plugins_opac_js, 'Koha::Plugin::Test::opac_js' ) != -1, 'Test plugin opac_js return value is part of code returned by get_plugins_opac_js' ); ok( index( $plugin->get_plugins_opac_head, 'Koha::Plugin::Test::opac_head' ) != -1, 'Test plugin opac_head return value is part of code returned by get_plugins_opac_head' ); +ok( index( $plugin->get_plugins_intranet_js, 'Koha::Plugin::Test::intranet_js' ) != -1, 'Test plugin intranet_js return value is part of code returned by get_plugins_intranet_js' ); +ok( index( $plugin->get_plugins_intranet_head, 'Koha::Plugin::Test::intranet_head' ) != -1, 'Test plugin intranet_head return value is part of code returned by get_plugins_intranet_head' ); t::lib::Mocks::mock_preference('UseKohaPlugins',0); t::lib::Mocks::mock_config('enable_plugins',0); is( $plugin->get_plugins_opac_js, q{}, 'Test plugin opac_js return value is empty' ); is( $plugin->get_plugins_opac_head, q{}, 'Test plugin opac_head return value is empty' ); +is( $plugin->get_plugins_intranet_js, q{}, 'Test plugin intranet_js return value is empty' ); +is( $plugin->get_plugins_intranet_head, q{}, 'Test plugin intranet_head return value is empty' ); diff --git a/t/db_dependent/Plugins.t b/t/db_dependent/Plugins.t index e4e987e013..e450a69633 100755 --- a/t/db_dependent/Plugins.t +++ b/t/db_dependent/Plugins.t @@ -47,6 +47,8 @@ ok( $plugin->can('opac_online_payment_begin'), 'Test plugin can opac_online_paym ok( $plugin->can('opac_online_payment_end'), 'Test plugin can opac_online_payment_end' ); ok( $plugin->can('opac_head'), 'Test plugin can opac_head' ); ok( $plugin->can('opac_js'), 'Test plugin can opac_js' ); +ok( $plugin->can('intranet_head'), 'Test plugin can intranet_head' ); +ok( $plugin->can('intranet_js'), 'Test plugin can intranet_js' ); ok( $plugin->can('configure'), 'Test plugin can configure' ); ok( $plugin->can('install'), 'Test plugin can install' ); ok( $plugin->can('upgrade'), 'Test plugin can upgrade' ); diff --git a/t/lib/Koha/Plugin/Test.pm b/t/lib/Koha/Plugin/Test.pm index 180df57915..7bf51df1df 100644 --- a/t/lib/Koha/Plugin/Test.pm +++ b/t/lib/Koha/Plugin/Test.pm @@ -70,6 +70,16 @@ sub opac_js { return "Koha::Plugin::Test::opac_js"; } +sub intranet_head { + my ( $self, $args ) = @_; + return "Koha::Plugin::Test::intranet_head"; +} + +sub intranet_js { + my ( $self, $args ) = @_; + return "Koha::Plugin::Test::intranet_js"; +} + sub configure { my ( $self, $args ) = @_; return "Koha::Plugin::Test::configure";; -- 2.39.5