View | Details | Raw Unified | Return to bug 40095
Collapse All | Expand All

(-)a/Koha/Template/Plugin/KohaPlugins.pm (-1 / +9 lines)
Lines 24-29 use base qw( Template::Plugin ); Link Here
24
use Try::Tiny qw( catch try );
24
use Try::Tiny qw( catch try );
25
25
26
use Koha::Plugins;
26
use Koha::Plugins;
27
use Koha::AuthUtils qw( get_script_name );
27
28
28
=head1 NAME
29
=head1 NAME
29
30
Lines 151-159 sub get_plugins_intranet_head { Link Here
151
This method collects the output of all plugins with an intranet_js method
152
This method collects the output of all plugins with an intranet_js method
152
to output to the javascript section of at the bottom of intranet pages.
153
to output to the javascript section of at the bottom of intranet pages.
153
154
155
The method now passes the current script name (controller) to the plugin's intranet_js
156
method as a parameter: { page => 'script_name' }
157
154
=cut
158
=cut
155
159
156
sub get_plugins_intranet_js {
160
sub get_plugins_intranet_js {
161
    my ($self) = @_;
157
    return q{} unless C4::Context->config("enable_plugins");
162
    return q{} unless C4::Context->config("enable_plugins");
158
163
159
    my $p = Koha::Plugins->new();
164
    my $p = Koha::Plugins->new();
Lines 166-175 sub get_plugins_intranet_js { Link Here
166
        }
171
        }
167
    );
172
    );
168
173
174
    # Get script name (controller) instead of template name
175
    my $script_name = get_script_name() || '';
176
169
    my @data = ();
177
    my @data = ();
170
    foreach my $plugin (@plugins) {
178
    foreach my $plugin (@plugins) {
171
        try {
179
        try {
172
            my $datum = $plugin->intranet_js || q{};
180
            my $datum = $plugin->intranet_js( { page => $script_name } ) || q{};
173
            push( @data, $datum );
181
            push( @data, $datum );
174
        } catch {
182
        } catch {
175
            warn "Error calling 'intranet_js' on the " . $plugin->{class} . "plugin ($_)";
183
            warn "Error calling 'intranet_js' on the " . $plugin->{class} . "plugin ($_)";
(-)a/t/db_dependent/Koha/Template/Plugin/KohaPlugins.t (-2 / +27 lines)
Lines 3-9 Link Here
3
use Modern::Perl;
3
use Modern::Perl;
4
4
5
use Test::NoWarnings;
5
use Test::NoWarnings;
6
use Test::More tests => 19;
6
use Test::More tests => 20;
7
use Test::Warn;
7
use Test::Warn;
8
use CGI;
8
use CGI;
9
use File::Basename;
9
use File::Basename;
Lines 92-95 is( $plugin->get_plugins_opac_head, q{}, 'Test plugin opac_head return value Link Here
92
is( $plugin->get_plugins_intranet_js,   q{}, 'Test plugin intranet_js return value is empty' );
92
is( $plugin->get_plugins_intranet_js,   q{}, 'Test plugin intranet_js return value is empty' );
93
is( $plugin->get_plugins_intranet_head, q{}, 'Test plugin intranet_head return value is empty' );
93
is( $plugin->get_plugins_intranet_head, q{}, 'Test plugin intranet_head return value is empty' );
94
94
95
# Test intranet_js page parameter passing
96
t::lib::Mocks::mock_config( 'enable_plugins', 1 );
97
98
# Reset the mock to capture arguments
99
my $captured_args;
100
$mock_plugin->mock(
101
    'intranet_js',
102
    sub {
103
        my ( $self, $args ) = @_;
104
        $captured_args = $args;
105
        return "test";
106
    }
107
);
108
109
# Create plugin with context (minimal)
110
my $plugin_with_context = bless {}, 'Koha::Template::Plugin::KohaPlugins';
111
112
# Call get_plugins_intranet_js
113
my $result = $plugin_with_context->get_plugins_intranet_js();
114
115
# Verify that the plugin was called with page parameter containing script name
116
ok(
117
    defined $captured_args && ref($captured_args) eq 'HASH' && exists $captured_args->{page},
118
    'Plugin intranet_js method receives page parameter with script name'
119
);
120
95
$schema->storage->txn_rollback;
121
$schema->storage->txn_rollback;
96
- 

Return to bug 40095