Bugzilla – Attachment 183380 Details for
Bug 40095
It would be beneficial to send the page when calling intranet_js plugin hooks
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 40095: Add context to intranet_js plugin hook
Bug-40095-Add-context-to-intranetjs-plugin-hook.patch (text/plain), 4.12 KB, created by
Martin Renvoize (ashimema)
on 2025-06-19 13:00:39 UTC
(
hide
)
Description:
Bug 40095: Add context to intranet_js plugin hook
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2025-06-19 13:00:39 UTC
Size:
4.12 KB
patch
obsolete
>From 29dc2ef99672742056aad6dbf6ad91c54636329b Mon Sep 17 00:00:00 2001 >From: Martin Renvoize <martin.renvoize@openfifth.co.uk> >Date: Mon, 9 Jun 2025 15:03:54 +0100 >Subject: [PATCH] Bug 40095: Add context to intranet_js plugin hook > >The get_plugins_intranet_js method now passes the current script name >(controller) to plugins via a 'page' parameter, allowing plugins to >determine which page/controller is being displayed. > >This will allow plugin authors to only return JS that's relevant to the >current page when they wish to do so. > >Test plan: >1. Create a plugin with an intranet_js method that logs the received parameters >2. Navigate to different pages in the staff interface >3. Verify that the plugin receives the page parameter containing the script name >4. Confirm that the script name reflects the actual controller (e.g., > '/cgi-bin/koha/admin/admin-home.pl' when on the admin home page) >5. Run the test: prove t/db_dependent/Koha/Template/Plugin/KohaPlugins.t >6. Verify that the new test passes, confirming plugins receive the page parameter >--- > Koha/Template/Plugin/KohaPlugins.pm | 10 ++++++- > .../Koha/Template/Plugin/KohaPlugins.t | 28 ++++++++++++++++++- > 2 files changed, 36 insertions(+), 2 deletions(-) > >diff --git a/Koha/Template/Plugin/KohaPlugins.pm b/Koha/Template/Plugin/KohaPlugins.pm >index 63bbc2c6ff0..e8a4cfa8517 100644 >--- a/Koha/Template/Plugin/KohaPlugins.pm >+++ b/Koha/Template/Plugin/KohaPlugins.pm >@@ -24,6 +24,7 @@ use base qw( Template::Plugin ); > use Try::Tiny qw( catch try ); > > use Koha::Plugins; >+use Koha::AuthUtils qw( get_script_name ); > > =head1 NAME > >@@ -151,9 +152,13 @@ sub get_plugins_intranet_head { > This method collects the output of all plugins with an intranet_js method > to output to the javascript section of at the bottom of intranet pages. > >+The method now passes the current script name (controller) to the plugin's intranet_js >+method as a parameter: { page => 'script_name' } >+ > =cut > > sub get_plugins_intranet_js { >+ my ($self) = @_; > return q{} unless C4::Context->config("enable_plugins"); > > my $p = Koha::Plugins->new(); >@@ -166,10 +171,13 @@ sub get_plugins_intranet_js { > } > ); > >+ # Get script name (controller) instead of template name >+ my $script_name = get_script_name() || ''; >+ > my @data = (); > foreach my $plugin (@plugins) { > try { >- my $datum = $plugin->intranet_js || q{}; >+ my $datum = $plugin->intranet_js( { page => $script_name } ) || q{}; > push( @data, $datum ); > } catch { > warn "Error calling 'intranet_js' on the " . $plugin->{class} . "plugin ($_)"; >diff --git a/t/db_dependent/Koha/Template/Plugin/KohaPlugins.t b/t/db_dependent/Koha/Template/Plugin/KohaPlugins.t >index d8aa7b658e6..0b98f126ddd 100755 >--- a/t/db_dependent/Koha/Template/Plugin/KohaPlugins.t >+++ b/t/db_dependent/Koha/Template/Plugin/KohaPlugins.t >@@ -3,7 +3,7 @@ > use Modern::Perl; > > use Test::NoWarnings; >-use Test::More tests => 19; >+use Test::More tests => 20; > use Test::Warn; > use CGI; > use File::Basename; >@@ -92,4 +92,30 @@ is( $plugin->get_plugins_opac_head, q{}, 'Test plugin opac_head return value > is( $plugin->get_plugins_intranet_js, q{}, 'Test plugin intranet_js return value is empty' ); > is( $plugin->get_plugins_intranet_head, q{}, 'Test plugin intranet_head return value is empty' ); > >+# Test intranet_js page parameter passing >+t::lib::Mocks::mock_config( 'enable_plugins', 1 ); >+ >+# Reset the mock to capture arguments >+my $captured_args; >+$mock_plugin->mock( >+ 'intranet_js', >+ sub { >+ my ( $self, $args ) = @_; >+ $captured_args = $args; >+ return "test"; >+ } >+); >+ >+# Create plugin with context (minimal) >+my $plugin_with_context = bless {}, 'Koha::Template::Plugin::KohaPlugins'; >+ >+# Call get_plugins_intranet_js >+my $result = $plugin_with_context->get_plugins_intranet_js(); >+ >+# Verify that the plugin was called with page parameter containing script name >+ok( >+ defined $captured_args && ref($captured_args) eq 'HASH' && exists $captured_args->{page}, >+ 'Plugin intranet_js method receives page parameter with script name' >+); >+ > $schema->storage->txn_rollback; >-- >2.49.0
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 40095
:
183380
|
183411