Bug 35288 - ApplyFrameworkDefaults add plugin to add more fine grained defaults handling
Summary: ApplyFrameworkDefaults add plugin to add more fine grained defaults handling
Status: Needs Signoff
Alias: None
Product: Koha
Classification: Unclassified
Component: Cataloging (show other bugs)
Version: Main
Hardware: All All
: P5 - low enhancement (vote)
Assignee: Mark Hofstetter
QA Contact: Testopia
URL:
Keywords:
Depends on: 35289
Blocks:
  Show dependency treegraph
 
Reported: 2023-11-08 12:41 UTC by Mark Hofstetter
Modified: 2023-11-09 18:20 UTC (History)
3 users (show)

See Also:
Change sponsored?: Sponsored
Patch complexity: ---
Documentation contact:
Documentation submission:
Text to go in the release notes:
Version(s) released in:


Attachments
Bug 35288: ApplyFrameworkDefaults add plugin to add more fine grained defaults handling (4.69 KB, patch)
2023-11-09 11:04 UTC, Mark Hofstetter
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Mark Hofstetter 2023-11-08 12:41:47 UTC
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

so I suggest (and already wrote) a new plugin hook

(see https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=33669)
Comment 1 Mark Hofstetter 2023-11-09 11:04:39 UTC
Created attachment 158710 [details] [review]
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>
Comment 2 Mark Hofstetter 2023-11-09 14:41:42 UTC
another real life example using this plugin hook

https://github.com/HKS3/ApplyFrameworkDefaultsLibelle
Comment 3 Lucas Gass 2023-11-09 15:23:21 UTC
Mark,

Don't we need unit tests for this change?
Comment 4 Mark Hofstetter 2023-11-09 18:20:15 UTC
yes definitely, (there is always a but here, so here it comes) but

1. I just wanted to build a quick working prototype (needed for customer)
2. for the community to evaluate, if it's generally considered usefull
3. at the moment I am not sure how to test, as it's highly dependent on the UI 

if you could point me to a useful test strategy or a similar test which relies on changing the framework in Biblio Edit I'd be glad to make a test