diff --git a/Koha/Template/Plugin/KohaPlugins.pm b/Koha/Template/Plugin/KohaPlugins.pm index 2049529806..39b58a3f33 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 3e6e310f93..2e44493afa 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;