Bug 39870 - Add plugin hook for making arbitrary data available to notices
Summary: Add plugin hook for making arbitrary data available to notices
Status: Pushed to main
Alias: None
Product: Koha
Classification: Unclassified
Component: Plugin architecture (show other bugs)
Version: Main
Hardware: All All
: P5 - low enhancement
Assignee: Tomás Cohen Arazi (tcohen)
QA Contact: Lisette Scheer
URL:
Keywords:
Depends on:
Blocks: 40037
  Show dependency treegraph
 
Reported: 2025-05-09 14:31 UTC by Lisette Scheer
Modified: 2025-05-30 14:33 UTC (History)
2 users (show)

See Also:
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:


Attachments
Bug 39870: Unit tests (4.24 KB, patch)
2025-05-12 12:19 UTC, Tomás Cohen Arazi (tcohen)
Details | Diff | Splinter Review
Bug 39870: Add `notices_content()` plugin hook (2.18 KB, patch)
2025-05-12 12:19 UTC, Tomás Cohen Arazi (tcohen)
Details | Diff | Splinter Review
Bug 39870: Unit tests (4.28 KB, patch)
2025-05-12 14:39 UTC, David Nind
Details | Diff | Splinter Review
Bug 39870: Add `notices_content()` plugin hook (2.22 KB, patch)
2025-05-12 14:39 UTC, David Nind
Details | Diff | Splinter Review
Bug 39870: Unit tests (4.34 KB, patch)
2025-05-13 20:36 UTC, Lisette Scheer
Details | Diff | Splinter Review
Bug 39870: Add `notices_content()` plugin hook (2.28 KB, patch)
2025-05-13 20:36 UTC, Lisette Scheer
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
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.