https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=44117

--- Comment #1 from Lisette Scheer <[email protected]> ---
Created attachment 211800
  -->
https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=211800&action=edit
Bug 44117: Add a notices_content_variables plugin hook to describe the content
plugins add to notices

Plugins can add content to notices with the notices_content hook, as
plugin_content.<namespace>. The notice editor (bugs 36588 and 43395)
offers plugin_content.<namespace> for each enabled plugin with that
hook, but cannot know what the content holds: it depends on each call
(e.g. Rapido ILL only adds content to HOLD notices of holds on ILL
requests), and calling the hook to find out would need real data.

This adds a notices_content_variables hook, for plugins to describe it:

    sub notices_content_variables {
        my ( $self, $params ) = @_;    # { module => ..., letter_code => ... }
        return unless $params->{letter_code} =~ /^HOLD/;
        return {
            ill_request => { kind => 'object', class => 'Koha::ILL::Request' },
            title       => { kind => 'scalar' },
        };
    }

It returns the variables of the content the plugin adds to the notice,
with the types of Koha::Notice::Template::Variables, or nothing when
the plugin adds no content to the notice. Then:
- the field list of the notice editor offers these variables, under
  plugin_content.<namespace> (e.g. plugin_content.rapidoill.title, and
  the fields of plugin_content.rapidoill.ill_request), only in the
  notices the plugin adds content to
- checking a template reports the variables a plugin does not describe
  (e.g. plugin_content.rapidoill.titel), and plugin_content.<namespace>
  in notices the plugin adds no content to, as warnings
Plugins without the hook, or whose hook fails (which is logged), are
offered as before, without checking the content under their namespace.
Types the hook does not describe as the registry does (e.g. a plain
string instead of { kind => ... }) are taken as unknown, so that a plugin
cannot break the notice editor.

Test plan:
1. Apply the patch and restart services
2. Install the example plugin attached to this bug
   (notice-content-example.kpz): in Administration > Manage plugins,
   click "Upload plugin" and upload it. It adds a message and the hold to
   HOLD notices, as plugin_content.example, and describes them with the
   new hook
3. Edit HOLD (Holds) and open the Email template:
   => The field list has a ---plugin_content.example (Notice content
      example)--- group with plugin_content.example.message and the
      fields of plugin_content.example.hold (e.g.
      plugin_content.example.hold.reserve_id)
4. Add [% plugin_content.example.mesage %] and check the template:
   => A warning says plugin_content.example has no key mesage, listing
      its keys: hold, message
5. Replace it with [% plugin_content.example.message %], and preview the
   template with the ID of a hold:
   => The preview shows "This text comes from the Notice content example
      plugin"
6. Edit CHECKOUT (Circulation):
   => The field list has no plugin_content.example group
   => Adding [% plugin_content.example.message %] and checking the
      template warns that no enabled plugin adds content to this notice
      as plugin_content.example
7. prove t/db_dependent/Koha/Notice/Template/Variables.t
t/db_dependent/Koha/Notice/Template/Validator.t

Co-Authored-By: Claude Opus 5.5 <[email protected]>

-- 
You are receiving this mail because:
You are watching all bug changes.
_______________________________________________
Koha-bugs mailing list -- [email protected]
To unsubscribe send an email to [email protected]
website : http://www.koha-community.org/
git : http://git.koha-community.org/
bugs : http://bugs.koha-community.org/

Reply via email to