Bugzilla – Attachment 158710 Details for
Bug 35288
ApplyFrameworkDefaults add plugin to add more fine grained defaults handling
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 35288: ApplyFrameworkDefaults add plugin to add more fine grained defaults handling
Bug-35288-ApplyFrameworkDefaults-add-plugin-to-add.patch (text/plain), 4.69 KB, created by
Mark Hofstetter
on 2023-11-09 11:04:39 UTC
(
hide
)
Description:
Bug 35288: ApplyFrameworkDefaults add plugin to add more fine grained defaults handling
Filename:
MIME Type:
Creator:
Mark Hofstetter
Created:
2023-11-09 11:04:39 UTC
Size:
4.69 KB
patch
obsolete
>From 37e3c78f1c6ab41b7d8bc463dd53286abd5d0a21 Mon Sep 17 00:00:00 2001 >From: Mark Hofstetter <mark@hofstetter.at> >Date: Thu, 9 Nov 2023 11:45:00 +0100 >Subject: [PATCH] Bug 35288: ApplyFrameworkDefaults add plugin to add more fine > grained defaults handling > >The "new" ApplyFrameworkDefaults option is to coarse sometimes >ie quite often you also want to apply default values even if then field wasn't empty before >e.g. on duplicating a new controlnumber should be generated etc > >This patch adds a new plugin call 'framework_defaults_override' and tidies up the code a little > >Plugin call: >Koha::Plugins->call( 'framework_defaults_override', $tag, $subfield, $value, $form_mode ); > >ie marc tag, marc subfield, the "before value", the action which triggered the change >possible actions are new, duplicate, changed (Framework), imported (via SRU) > >the plugin has to return a hashref containing two keys > >apply_override - undef or a true if the default value from the framework should be applied >override_default_value - a completly new derived value > >sub framework_defaults_override { > my ( $self, $tag, $subfield, $value, $form_mode ) = @_; > # $framework_override->{override_default_value} > # $framework_override->{apply_override} > my $r = {override_default_value => undef, apply_override => undef}; > if ($tag eq '245' && $subfield eq 'a') { > $r->{apply_override} = 1; > $r->{override_default_value} = $value .' added'; > } > return $r; >} > >for a demo implementation please see >https://github.com/HKS3/hks3-munde-framework-defaults-demo/blob/main/hks3-munde-framework-defaults-demo.kpz > >To test: >1) apply patch >2) install demo plugin (and don't enable it yet) >3) create a record with a 245a field set to a value eg "My Title" >4) enable ApplyFrameworkDefaults for all 4 cases "Select all" >5) in Cataloging Edit the previously generated record >6) change framework via settings >7) nothing should happen to the title in 245a >8) enable plugin >9) repeat point 5+6 >10) the title in 245a should change to "My Title added" >11) please sign off > >Sponsored-by: Styrian State Library >Co-authored-by: Thomas Klausner <domm@plix.at> >--- > Koha/UI/Form/Builder/Biblio.pm | 39 ++++++++++++++++++++++------------ > 1 file changed, 26 insertions(+), 13 deletions(-) > >diff --git a/Koha/UI/Form/Builder/Biblio.pm b/Koha/UI/Form/Builder/Biblio.pm >index 340b27b27d..d8ed6471d8 100644 >--- a/Koha/UI/Form/Builder/Biblio.pm >+++ b/Koha/UI/Form/Builder/Biblio.pm >@@ -85,27 +85,40 @@ sub generate_subfield_form { > # based on the ApplyFrameworkDefaults setting. > # Substitute date parts, user name > my $applydefaults = C4::Context->preference('ApplyFrameworkDefaults'); >- if ( $value eq '' && ( >- ( $applydefaults =~ /new/ && !$self->{biblionumber} ) || >- ( $applydefaults =~ /duplicate/ && $op eq 'duplicate' ) || >- ( $applydefaults =~ /changed/ && $changed_framework ) || >- ( $applydefaults =~ /imported/ && $breedingid ) >- ) ) { >- $value = $tagslib->{$tag}->{$subfield}->{defaultvalue} // q{}; >+ >+ my $form_mode; >+ if ( !$self->{biblionumber} ) { >+ $form_mode = 'new'; >+ } elsif ( $op eq 'duplicate' ) { >+ $form_mode = 'duplicate'; >+ } elsif ($changed_framework) { >+ $form_mode = 'changed'; >+ } elsif ($breedingid) { >+ $form_mode = 'imported'; >+ } >+ >+ my ($framework_override) = >+ Koha::Plugins->call( 'framework_defaults_override', $tag, $subfield, $value, $form_mode ); >+ >+ if ( ( $value eq '' || $framework_override->{apply_override} ) >+ && ( $applydefaults =~ /$form_mode/ ) ) >+ { >+ $value = $framework_override->{override_default_value} // $tagslib->{$tag}->{$subfield}->{defaultvalue} // q{}; > > # get today date & replace <<YYYY>>, <<YY>>, <<MM>>, <<DD>> if provided in the default value >- my $today_dt = dt_from_string; >- my $year = $today_dt->strftime('%Y'); >+ my $today_dt = dt_from_string; >+ my $year = $today_dt->strftime('%Y'); > my $shortyear = $today_dt->strftime('%y'); >- my $month = $today_dt->strftime('%m'); >- my $day = $today_dt->strftime('%d'); >+ my $month = $today_dt->strftime('%m'); >+ my $day = $today_dt->strftime('%d'); > $value =~ s/<<YYYY>>/$year/g; > $value =~ s/<<YY>>/$shortyear/g; > $value =~ s/<<MM>>/$month/g; > $value =~ s/<<DD>>/$day/g; >+ > # And <<USER>> with surname (?) >- my $username=(C4::Context->userenv?C4::Context->userenv->{'surname'}:"superlibrarian"); >- $value=~s/<<USER>>/$username/g; >+ my $username = ( C4::Context->userenv ? C4::Context->userenv->{'surname'} : "superlibrarian" ); >+ $value =~ s/<<USER>>/$username/g; > } > > my $dbh = C4::Context->dbh; >-- >2.20.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 35288
:
158710
|
176105