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 Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
This commit is contained in:
parent
adcc5d6273
commit
d0fecf3ff7
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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' %]
|
||||
<title>
|
||||
|
|
@ -280,8 +283,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>
|
||||
|
||||
|
|
@ -951,9 +954,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 %]
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue