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

(-)a/Koha/Plugins/Tab.pm (+72 lines)
Line 0 Link Here
1
package Koha::Plugins::Tab;
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it under the
6
# terms of the GNU General Public License as published by the Free Software
7
# Foundation; either version 3 of the License, or (at your option) any later
8
# version.
9
#
10
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
13
#
14
# You should have received a copy of the GNU General Public License along
15
# with Koha; if not, write to the Free Software Foundation, Inc.,
16
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
18
19
use Modern::Perl;
20
21
use Koha::Exceptions;
22
23
use base qw(Class::Accessor);
24
25
__PACKAGE__->mk_accessors(qw( title content id ));
26
27
=head1 NAME
28
29
Koha::Plugins::Tab - Simple base to abstract tabs to be generated by plugins
30
31
=head1 DESCRIPTION
32
33
Object-oriented class that represents tabs generated by plugins. Error handling on
34
mandatory fields is handled here.
35
36
=head1 API
37
38
=head2 Class methods
39
40
=head3 new
41
42
    my $tab = Koha::Plugins::Tab->new(
43
        {
44
            title   => 'A title',
45
            content => 'Some content'
46
        }
47
    );
48
49
Returns a Koha::Plugins::Tab object representing a plugin-generated tab.
50
51
=cut
52
53
sub new {
54
55
    my ( $class, $params )  = @_;
56
57
    Koha::Exceptions::MissingParameter->throw( "Mandatory parameter 'title' missing" )
58
        unless defined $params->{ title };
59
60
    Koha::Exceptions::MissingParameter->throw( "Mandatory parameter 'content' missing")
61
      unless defined $params->{content};
62
63
    my $self = {
64
        title   => $params->{title},
65
        content => $params->{content}
66
    };
67
68
    bless $self, $class;
69
    return $self;
70
}
71
72
1;
(-)a/catalogue/detail.pl (-5 / +13 lines)
Lines 75-86 if ( C4::Context->preference('UseKohaPlugins') && Link Here
75
    });
75
    });
76
    my @tabs;
76
    my @tabs;
77
    foreach my $tab_plugin (@tab_plugins) {
77
    foreach my $tab_plugin (@tab_plugins) {
78
        my @biblio_tabs = $tab_plugin->intranet_catalog_biblio_tab();
78
        my @biblio_tabs;
79
        foreach my $tab (@biblio_tabs) {
79
80
            $tab->{id} = 'tab-' . $tab->{title};
80
        try {
81
            $tab->{id} =~ s/[^0-9A-Za-z]+/-/g;
81
            @biblio_tabs = $tab_plugin->intranet_catalog_biblio_tab();
82
            push @tabs, $tab,
82
            foreach my $tab (@biblio_tabs) {
83
                my $tab_id = 'tab-' . $tab->title;
84
                $tab_id =~ s/[^0-9A-Za-z]+/-/g;
85
                $tab->id( $tab_id );
86
                push @tabs, $tab,
87
            }
83
        }
88
        }
89
        catch {
90
            warn "Error calling 'intranet_catalog_biblio_tab' on the " . $tab_plugin->{class} . "plugin ($_)";
91
        };
84
    }
92
    }
85
93
86
    $template->param(
94
    $template->param(
(-)a/t/Koha/Plugins/Tab.t (+62 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18
use Modern::Perl;
19
20
use Test::More tests => 1;
21
use Test::Exception;
22
23
use Koha::Plugins::Tab;
24
25
subtest 'new() tests' => sub {
26
    plan tests => 7;
27
28
    throws_ok { Koha::Plugins::Tab->new( { title => 'A title' } ); }
29
    'Koha::Exceptions::MissingParameter',
30
      'Exception is thrown on missing content';
31
32
    is(
33
        "$@",
34
        "Mandatory parameter 'content' missing",
35
        'Exception message is correct'
36
    );
37
38
    throws_ok { Koha::Plugins::Tab->new( { content => 'Some content' } ); }
39
    'Koha::Exceptions::MissingParameter',
40
      'Exception is thrown on missing title';
41
42
    is(
43
        "$@",
44
        "Mandatory parameter 'title' missing",
45
        'Exception message is correct'
46
    );
47
48
    my $tab = Koha::Plugins::Tab->new(
49
        {
50
            title   => 'A title',
51
            content => 'Some content'
52
        }
53
    );
54
55
    is( $tab->title, 'A title', 'title accessor is correct' );
56
    is( $tab->content, 'Some content', 'content accessor is correct' );
57
58
    my $id = 'calculated-id';
59
    $tab->id($id);
60
61
    is( $tab->id, $id, 'The id can be calculated and set on runtime' );
62
};
(-)a/t/lib/Koha/Plugin/Test.pm (-2 / +23 lines)
Lines 4-9 package Koha::Plugin::Test; Link Here
4
use Modern::Perl;
4
use Modern::Perl;
5
5
6
use Koha::Exceptions::Exception;
6
use Koha::Exceptions::Exception;
7
use Koha::Plugins::Tab;
8
7
use Mojo::JSON qw(decode_json);
9
use Mojo::JSON qw(decode_json);
8
10
9
## Required for all plugins
11
## Required for all plugins
Lines 139-145 sub after_biblio_action { Link Here
139
    }
141
    }
140
}
142
}
141
143
142
143
sub after_item_action {
144
sub after_item_action {
144
    my ( $self, $params ) = @_;
145
    my ( $self, $params ) = @_;
145
    my $action  = $params->{action} // '';
146
    my $action  = $params->{action} // '';
Lines 228-233 sub check_password { Link Here
228
    }
229
    }
229
}
230
}
230
231
232
sub intranet_catalog_biblio_tab {
233
    my @tabs;
234
    push @tabs,
235
      Koha::Plugins::Tab->new(
236
        {
237
            title   => 'Tab 1',
238
            content => 'This is content for tab 1'
239
        }
240
      );
241
242
    push @tabs,
243
      Koha::Plugins::Tab->new(
244
        {
245
            title   => 'Tab 2',
246
            content => 'This is content for tab 2'
247
        }
248
      );
249
250
    return @tabs;
251
}
252
231
sub _private_sub {
253
sub _private_sub {
232
    return "";
254
    return "";
233
}
255
}
234
- 

Return to bug 23050