Bug 35568: Add a transform_prepared_letter plugin hook to allow modification of notic...
authorKyle M Hall <kyle@bywatersolutions.com>
Thu, 14 Dec 2023 11:58:40 +0000 (11:58 +0000)
committerKatrin Fischer <katrin.fischer@bsz-bw.de>
Mon, 22 Apr 2024 06:57:38 +0000 (08:57 +0200)
commitad1d8fd561f464484ec5683505d2d86d8db8363e
tree76f327a6a76681f0b775175d11be6543bfb805dc
parentad62f81b03ff51d62d6d43ebbae120b7b85e8909
Bug 35568: Add a transform_prepared_letter plugin hook to allow modification of notices created via GetPreparedLetter

A plugin hook for GetPreparedLetter would be very useful. It could be used to add universal headers and/or footers to messages, attach news, and modify notices in other ways in whole or in part. It could even be used for call webhooks when certain types of notices are sent.

For example, the MessageBee ( https://uniquelibrary.com/messagebee/ ) plugin for Koha generates YAML based notice content, which is then further processed by the before_send_messages hook. This process is unreliable due to the possible changes in data between the creation of the yaml and the reading of that yaml and transforming it into JSON with much more data. For example, the yaml may contain an issue_id, but that checkout may have been returned in the meantime. A hook like this would allow the MessageBee plugin to skip the yaml step and create the json data directly which is then sent to MessageBee for transmission to the patron.

Test Plan:
1) Apply this patch
2) prove t/db_dependent/Koha/Plugins/Transform_prepared_letter_hook.t
3) Download and install the Kitchen Sink plugin v2.4.0
   https://github.com/bywatersolutions/dev-koha-plugin-kitchen-sink/releases/tag/v2.4.0
4) Generate any notice or slip, such as a checkin or checkout notice
5) Note that all notices now end with "Thanks for using your local library!"

Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
C4/Letters.pm
t/db_dependent/Koha/Plugins/Transform_prepared_letter_hook.t [new file with mode: 0755]
t/lib/plugins/Koha/Plugin/Test.pm