Bug 39870

Summary: Add plugin hook for making arbitrary data available to notices
Product: Koha Reporter: Lisette Scheer <lisette>
Component: Plugin architectureAssignee: Tomás Cohen Arazi (tcohen) <tomascohen>
Status: Pushed to main --- QA Contact: Lisette Scheer <lisette>
Severity: enhancement    
Priority: P5 - low CC: michaela.sieber, tomascohen
Version: Main   
Hardware: All   
OS: All   
GIT URL: Change sponsored?: ---
Patch complexity: Small patch Documentation contact:
Documentation submission: Text to go in the release notes:
This development allows plugins to make arbitrary data available to notices. Each plugin has a defined namespace (e.g. 'innreach'). If a plugin implements the `notices_content` method, it will be called. The generated data structure it returns will be available to the notice author as `[% plugin_content.innreach %]`. The hook will be passed the notice generation context, so authors can return different information based on what they need for each letter, for example.
Version(s) released in:
25.05.00
Circulation function:
Bug Depends on:    
Bug Blocks: 40037    
Attachments: Bug 39870: Unit tests
Bug 39870: Add `notices_content()` plugin hook
Bug 39870: Unit tests
Bug 39870: Add `notices_content()` plugin hook
Bug 39870: Unit tests
Bug 39870: Add `notices_content()` plugin hook

Description Lisette Scheer 2025-05-09 14:31:06 UTC
This enhancement would add a plugin hook that could add 'plugin_data' or something to notices so plugins can return information into notices as the plugin needs something like this:

[% plugin_content.plugin_name.value %]
Comment 1 Tomás Cohen Arazi (tcohen) 2025-05-12 12:19:42 UTC
Created attachment 182265 [details] [review]
Bug 39870: Unit tests
Comment 2 Tomás Cohen Arazi (tcohen) 2025-05-12 12:19:45 UTC
Created attachment 182266 [details] [review]
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
Comment 3 David Nind 2025-05-12 14:39:49 UTC
Created attachment 182293 [details] [review]
Bug 39870: Unit tests

Signed-off-by: David Nind <david@davidnind.com>
Comment 4 David Nind 2025-05-12 14:39:52 UTC
Created attachment 182294 [details] [review]
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

Signed-off-by: David Nind <david@davidnind.com>
Comment 5 Lisette Scheer 2025-05-13 20:36:23 UTC
Created attachment 182418 [details] [review]
Bug 39870: Unit tests

Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Lisette Scheer <lisette@bywatersolutions.com>
Comment 6 Lisette Scheer 2025-05-13 20:36:26 UTC
Created attachment 182419 [details] [review]
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

Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Lisette Scheer <lisette@bywatersolutions.com>
Comment 7 Lisette Scheer 2025-05-13 20:37:45 UTC
Worked great and this will be great for passing ILL information to notices from plugins.
Comment 8 Katrin Fischer 2025-05-15 07:13:57 UTC
Please update https://wiki.koha-community.org/wiki/Koha_Plugin_Hooks!
Comment 9 Katrin Fischer 2025-05-15 07:21:47 UTC
Pushed for 25.05!

Well done everyone, thank you!
Comment 10 Michaela Sieber 2025-05-23 09:13:15 UTC
I added a line under Implemented hooks on the wiki page https://wiki.koha-community.org/wiki/Koha_Plugin_Hooks

Please review if everything is correct.
Comment 11 Katrin Fischer 2025-05-23 11:30:29 UTC
Thanks! We still need release notes!
Comment 12 Tomás Cohen Arazi (tcohen) 2025-05-23 11:57:33 UTC
Thank you both.
Comment 13 Tomás Cohen Arazi (tcohen) 2025-05-23 11:58:17 UTC
(In reply to Katrin Fischer from comment #11)
> Thanks! We still need release notes!

And this should go to the manual I guess.