[Koha-bugs] [Bug 28010] New: add plugin to modify record in "opac-detail.pl"

bugzilla-daemon at bugs.koha-community.org bugzilla-daemon at bugs.koha-community.org
Sat Mar 20 22:21:35 CET 2021


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

            Bug ID: 28010
           Summary: add plugin to modify record in "opac-detail.pl"
 Change sponsored?: ---
           Product: Koha
           Version: unspecified
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P5 - low
         Component: Plugin architecture
          Assignee: koha-bugs at lists.koha-community.org
          Reporter: koha at trust-box.at
        QA Contact: testopia at bugs.koha-community.org

Created attachment 118560
  -->
https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=118560&action=edit
patch to opac-detail.pl

I (guess I) need the abiltiy to change how records are beeing display in in
opac-detail.pl

Specifically I want to change the content of a record depending if a user is
logged in or not for ebook renting

So it would be great to have the ability to have a plugin hook there, something
like

  1 diff --git a/opac-detail.pl.orig b/opac-detail.pl
  2 index e74cf4b..b46eb90 100755
  3 --- a/opac-detail.pl.orig
  4 +++ b/opac-detail.pl
  5 @@ -217,6 +217,16 @@ if ( $xslfile ) {
  6          $variables = { %$variables, %$plugin_variables };
  7      }
  8
  9 +    $record = Koha::Plugins->call_apply(
 10 +        'munge_record',
 11 +        $record,
 12 +        {
 13 +            patron      => $patron,
 14 +            interface   => 'opac',
 15 +            caller      => 'opac-detail',
 16 +        }
 17 +    );
 18 +


additionally I have a proposal to extend/modify the plugin system a little bit:

I don't like the idea very much that the caller of a plugin has to take care of
merging the results so the first step would be to add the ability that a plugin
works recursively on a variable


diff --git a/Plugins.pm.orig b/Plugins.pm
index 11d44dc..71461de 100644
--- a/Plugins.pm.orig
+++ b/Plugins.pm
@@ -82,6 +82,35 @@ sub call {
     return @responses;
 }

+=head2 call_apply
+
+Calls a plugin method for all enabled plugins, reworking on the same input and
returning it.
+ideally the caller of a plugin must not know how to merge the results
+so maybe also implement a "merge" method in the plugin
+
+    @responses = Koha::Plugins->call_apply($method, $work_var, @args)
+
+=cut
+
+sub call_apply {
+    my ($class, $method, $work_var, @args) = @_;
+
+    if (C4::Context->config('enable_plugins')) {
+        my @plugins = $class->new({ enable_plugins => 1 })->GetPlugins({
method => $method });
+        @plugins = grep { $_->can($method) } @plugins;
+        foreach my $plugin (@plugins) {
+            my $work_var = eval { $plugin->$method($work_var, @args) };
+            if ($@) {
+                warn sprintf("Plugin error (%s): %s",
$plugin->get_metadata->{name}, $@);
+                next;
+            }
+        }
+
+    }
+    return $work_var;
+}
+
+

 =head2 GetPlugins


In another my idea would be to have an optional "merge" method for a certain
type of plugins to avoid code like

 206
 207     my @plugin_responses = Koha::Plugins->call(
 208         'opac_detail_xslt_variables',
 209         {
 210             biblio_id => $biblionumber,
 211             lang      => $lang,
 212             patron_id => $borrowernumber
 213
 214         }
 215     );
 216     for my $plugin_variables ( @plugin_responses ) {
 217         $variables = { %$variables, %$plugin_variables };
 218     }
 219

and be able to write something along the lines of

 206
 207     my $variables = Koha::Plugins->call(
 208         'opac_detail_xslt_variables',
+            $variables, 
 209         {
 210             biblio_id => $biblionumber,
 211             lang      => $lang,
 212             patron_id => $borrowernumber
 213
 214         }
 215     );


I hope I haven't packed to much into one issue, thanks a lot

-- 
You are receiving this mail because:
You are the assignee for the bug.
You are watching all bug changes.


More information about the Koha-bugs mailing list