From 25658719905eb70b5e3c7ef052966b549d7ddde1 Mon Sep 17 00:00:00 2001 From: Pasi Kallinen Date: Wed, 5 Feb 2020 09:32:38 +0200 Subject: [PATCH] Bug 24589: Add plugin hook addbiblio_check_record Adds a new plugin hook, addbiblio_check_record, to addbiblio.pl. When saving a record, the hook is called with the MARC record as a parameter. If the hook returns anything, the return values are shown to the user, and saving the record is prevented. This can be used to create plugins that eg. check or modify the record. Advanced editor has not been changed. --- cataloguing/addbiblio.pl | 30 ++++++++++++++++++++++ .../prog/en/modules/cataloguing/addbiblio.tt | 10 ++++++++ 2 files changed, 40 insertions(+) diff --git a/cataloguing/addbiblio.pl b/cataloguing/addbiblio.pl index cd53c66e70..ae6da5cd58 100755 --- a/cataloguing/addbiblio.pl +++ b/cataloguing/addbiblio.pl @@ -41,6 +41,8 @@ use Koha::ItemTypes; use Koha::Libraries; use Koha::BiblioFrameworks; +use Koha::Plugins; +use Koha::Plugins::Handler; use Date::Calc qw(Today); use MARC::File::USMARC; @@ -832,6 +834,34 @@ if ( $op eq "addbiblio" ) { # getting html input my @params = $input->multi_param(); $record = TransformHtmlToMarc( $input, 1 ); + + if ( $record ne '-1' && C4::Context->preference('UseKohaPlugins') && + C4::Context->config('enable_plugins') ) { + my @formaterrors; + my @plugins = Koha::Plugins->new()->GetPlugins({ + method => 'addbiblio_check_record' + }); + foreach my $plugin (@plugins) { + push(@formaterrors, @{$plugin->addbiblio_check_record($record)}); + } + if (scalar(@formaterrors) > 0) { + $template->param( + marc_format_errors => \@formaterrors, + title => $record->title, + popup => $mode, + frameworkcode => $frameworkcode, + itemtype => $frameworkcode, + borrowernumber => $loggedinuser, + biblionumber => $biblionumber, + tab => scalar $input->param('tab') + ); + $template->{'VARS'}->{'searchid'} = $searchid; + build_tabs ($template, $record, $dbh,$encoding,$input); + output_html_with_http_headers $input, $cookie, $template->output; + exit; + } + } + # check for a duplicate my ( $duplicatebiblionumber, $duplicatetitle ); if ( !$is_a_modif ) { diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/addbiblio.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/addbiblio.tt index 4fda2747a9..2ab129730b 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/addbiblio.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/addbiblio.tt @@ -687,6 +687,16 @@ [% END %] + [% IF marc_format_errors %] +
+ +
+ [% END %] + [% IF ( popup ) %] [% END %] -- 2.11.0