From 962f6dc31af1f530973da5a7a455ff4780077434 Mon Sep 17 00:00:00 2001 From: Fridolin Somers Date: Mon, 30 Nov 2020 08:39:41 +0100 Subject: [PATCH] Bug 27114: Use Template Toolkit plugin for Koha plugins hook 'intranet_catalog_biblio_tab' Koha plugins hook 'intranet_catalog_biblio_tab' is for a template, it will be better it uses Template Toolkit plugin like intranet_js, ... It will allow using it in other places like MARC details page for example. Test plan uses a plugin from git.biblibre.com because this hook is not yet in KitchenSink. Test plan : 1) Enable Koha plugins 2) Download and install the latest version of this plugin https://git.biblibre.com/biblibre/koha-plugin-intranet-detail-hook 3) Browse to catalogue/detail.pl for a record 4) Note you see two new tabs with content --- Koha/Template/Plugin/KohaPlugins.pm | 37 +++++++++++++++++++ catalogue/detail.pl | 23 ------------ .../prog/en/modules/catalogue/detail.tt | 13 ++++--- 3 files changed, 45 insertions(+), 28 deletions(-) diff --git a/Koha/Template/Plugin/KohaPlugins.pm b/Koha/Template/Plugin/KohaPlugins.pm index 798e648a17..157d6bca0b 100644 --- a/Koha/Template/Plugin/KohaPlugins.pm +++ b/Koha/Template/Plugin/KohaPlugins.pm @@ -21,6 +21,8 @@ use Modern::Perl; use base qw( Template::Plugin ); +use Try::Tiny; + use Koha::Plugins; =head1 NAME @@ -145,4 +147,39 @@ sub get_plugins_intranet_js { return join( "\n", @data ); } +sub get_plugins_intranet_catalog_biblio_tab { + + my $tabs = []; + + return $tabs unless C4::Context->config("enable_plugins"); + + my $p = Koha::Plugins->new(); + return $tabs unless $p; + + my @plugins = $p->GetPlugins( + { + method => 'intranet_catalog_biblio_tab', + } + ); + + foreach my $plugin (@plugins) { + try { + my @newtabs = $plugin->intranet_catalog_biblio_tab(); + foreach my $newtab (@newtabs) { + # Add a unique HTML id + my $html_id = 'tab-'. $plugin->{class} . '-' . $newtab->title; + # Using characters except ASCII letters, digits, '_', '-' and '.' may cause compatibility problems + $html_id =~ s/[^0-9A-Za-z]+/-/g; + $newtab->id($html_id); + } + push @$tabs, @newtabs; + } + catch { + warn "Error calling 'intranet_catalog_biblio_tab' on the " . $plugin->{class} . "plugin ($_)"; + }; + } + + return $tabs; +} + 1; diff --git a/catalogue/detail.pl b/catalogue/detail.pl index 7b7f4d2944..2621384645 100755 --- a/catalogue/detail.pl +++ b/catalogue/detail.pl @@ -70,31 +70,8 @@ if ( C4::Context->config('enable_plugins') ) { my @plugins = Koha::Plugins->new()->GetPlugins({ method => 'intranet_catalog_biblio_enhancements_toolbar_button' }); - - my @tab_plugins = Koha::Plugins->new()->GetPlugins({ - method => 'intranet_catalog_biblio_tab', - }); - my @tabs; - foreach my $tab_plugin (@tab_plugins) { - my @biblio_tabs; - - try { - @biblio_tabs = $tab_plugin->intranet_catalog_biblio_tab(); - foreach my $tab (@biblio_tabs) { - my $tab_id = 'tab-' . $tab->title; - $tab_id =~ s/[^0-9A-Za-z]+/-/g; - $tab->id( $tab_id ); - push @tabs, $tab, - } - } - catch { - warn "Error calling 'intranet_catalog_biblio_tab' on the " . $tab_plugin->{class} . "plugin ($_)"; - }; - } - $template->param( plugins => \@plugins, - tabs => \@tabs, ); } diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt index 5c0f779436..abc5cf7dd6 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt @@ -2,6 +2,7 @@ [% USE Asset %] [% USE Koha %] [% USE KohaDates %] +[% USE KohaPlugins %] [% USE AuthorisedValues %] [% USE Branches %] [% USE Biblio %] @@ -30,6 +31,8 @@ [% END %] [% END %] +[% SET plugins_intranet_catalog_biblio_tabs = KohaPlugins.get_plugins_intranet_catalog_biblio_tab %] + [% SET footerjs = 1 %] [% INCLUDE 'doc-head-open.inc' %] Koha › Catalog › @@ -257,8 +260,8 @@ [% IF ( Koha.Preference('NovelistSelectStaffEnabled') && Koha.Preference('NovelistSelectStaffProfile') && Koha.Preference('NovelistSelectStaffView') == 'tab' ) %] <li class="NovelistSelect" style="display:none;"><a href="#NovelistSelect">NoveList Select</a></li> [% END %] -[% FOREACH tab IN tabs %] - <li><a href="#[% tab.id | uri %]">[% tab.title | html %]</a></li> +[% FOREACH plugins_intranet_catalog_biblio_tab IN plugins_intranet_catalog_biblio_tabs %] + <li><a href="#[% plugins_intranet_catalog_biblio_tab.id | uri %]">[% plugins_intranet_catalog_biblio_tab.title | html %]</a></li> [% END %] </ul> @@ -933,9 +936,9 @@ Note that permanent location is a code, and location may be an authval. </div> [% END %] -[% FOREACH tab IN tabs %] - <div id="[% tab.id | html %]"> - [% tab.content | $raw %] +[% FOREACH plugins_intranet_catalog_biblio_tab IN plugins_intranet_catalog_biblio_tabs %] + <div id="[% plugins_intranet_catalog_biblio_tab.id | html %]"> + [% plugins_intranet_catalog_biblio_tab.content | $raw %] </div> [% END %] -- 2.29.2