From e357ec91ae76cb569fe66253aa50b43ceaf2dc8b Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Fri, 9 May 2025 17:10:49 -0300 Subject: [PATCH] Bug 39870: Add `notices_content()` plugin hook This patch adds a hook for adding information to notices context from plugins. The method is passed all the `GetPreparedLetter()` paramerters so it gets all the context for calculating the values to pass the template. The main target use for this hook is ILL, where we need to identify candidate ILL requests related to the filled hold for printing the right ILL-related message. The implementation is generic so it can be used for any other use case. To test: 1. Apply the unit tests 2. Run: $ ktd --shell k$ prove t/db_dependent/Koha/Plugins/Notices_content_hook.t => FAIL: The hook is not implemented, the letter doesn't include plugin-calculated data the tests expect. 3. Apply this patch 4. Repeat 2 => SUCCESS: Tests pass! 5. Sign off :-D --- C4/Letters.pm | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/C4/Letters.pm b/C4/Letters.pm index 9a4a0ee104c..b7c6b0cedd1 100644 --- a/C4/Letters.pm +++ b/C4/Letters.pm @@ -623,6 +623,30 @@ sub GetPreparedLetter { $objects->{librarian} = Koha::Patrons->find( C4::Context->userenv->{number} ) if ($userenv); } + # add plugin-generated objects + if ( C4::Context->config("enable_plugins") ) { + my @plugins = Koha::Plugins->new->GetPlugins( + { + method => 'notices_content', + } + ); + + if (@plugins) { + foreach my $plugin (@plugins) { + my $namespace = $plugin->get_metadata()->{namespace}; + if ($namespace) { + try { + if ( my $content = $plugin->notices_content( \%params ) ) { + $objects->{plugin_content}->{$namespace} = $content; + } + } catch { + next; + }; + } + } + } + } + # Best guess at language 'default' notice is written for include handling if ( $lang eq 'default' ) { -- 2.49.0