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

(-)a/C4/Letters.pm (-1 / +25 lines)
Lines 1518-1524 sub _process_tt { Link Here
1518
1518
1519
    my $tt_params = { %{ _get_tt_params( $tables ) }, %{ _get_tt_params( $loops, 'is_a_loop' ) }, %$substitute };
1519
    my $tt_params = { %{ _get_tt_params( $tables ) }, %{ _get_tt_params( $loops, 'is_a_loop' ) }, %$substitute };
1520
1520
1521
    $content = qq|[% USE KohaDates %]$content|;
1521
    $content = add_tt_filters( $content );
1522
    $content = qq|[% USE KohaDates %][% USE Remove_MARC_punctuation %]$content|;
1522
1523
1523
    my $output;
1524
    my $output;
1524
    $template->process( \$content, $tt_params, \$output ) || croak "ERROR PROCESSING TEMPLATE: " . $template->error();
1525
    $template->process( \$content, $tt_params, \$output ) || croak "ERROR PROCESSING TEMPLATE: " . $template->error();
Lines 1545-1550 sub _get_tt_params { Link Here
1545
            plural   => 'biblios',
1546
            plural   => 'biblios',
1546
            pk       => 'biblionumber',
1547
            pk       => 'biblionumber',
1547
        },
1548
        },
1549
        biblioitems => {
1550
            module   => 'Koha::Biblioitems',
1551
            singular => 'biblioitem',
1552
            plural   => 'biblioitems',
1553
            pk       => 'biblioitemnumber',
1554
        },
1548
        borrowers => {
1555
        borrowers => {
1549
            module   => 'Koha::Patrons',
1556
            module   => 'Koha::Patrons',
1550
            singular => 'borrower',
1557
            singular => 'borrower',
Lines 1694-1699 sub _get_tt_params { Link Here
1694
    return $params;
1701
    return $params;
1695
}
1702
}
1696
1703
1704
=head3 add_tt_filters
1705
1706
$content = add_tt_filters( $content );
1707
1708
Add TT filters to some specific fields if needed.
1709
1710
For now we only add the Remove_MARC_punctuation TT filter to biblio and biblioitem fields
1711
1712
=cut
1713
1714
sub add_tt_filters {
1715
    my ( $content ) = @_;
1716
    $content =~ s|\[%\s*biblio\.(.*?)\s*%\]|[% biblio.$1 \| \$Remove_MARC_punctuation %]|gxms;
1717
    $content =~ s|\[%\s*biblioitem\.(.*?)\s*%\]|[% biblioitem.$1 \| \$Remove_MARC_punctuation %]|gxms;
1718
    return $content;
1719
}
1720
1697
=head2 get_item_content
1721
=head2 get_item_content
1698
1722
1699
    my $item = Koha::Items->find(...)->unblessed;
1723
    my $item = Koha::Items->find(...)->unblessed;
(-)a/Koha/Template/Plugin/Remove_MARC_punctuation.pm (+31 lines)
Line 0 Link Here
1
package Koha::Template::Plugin::Remove_MARC_punctuation;
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 Template::Plugin::Filter;
21
use base qw( Template::Plugin::Filter );
22
23
our $DYNAMIC = 1;
24
25
sub filter {
26
    my ( $self, $value ) = @_;
27
    $value =~ s/\p{P}$//;
28
    return $value;
29
}
30
31
1;
(-)a/t/db_dependent/Letters/TemplateToolkit.t (-2 / +41 lines)
Lines 19-25 Link Here
19
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
# along with Koha; if not, see <http://www.gnu.org/licenses>.
20
20
21
use Modern::Perl;
21
use Modern::Perl;
22
use Test::More tests => 17;
22
use Test::More tests => 18;
23
use Test::Warn;
23
use Test::Warn;
24
24
25
use MARC::Record;
25
use MARC::Record;
Lines 894-899 subtest 'loops' => sub { Link Here
894
    };
894
    };
895
};
895
};
896
896
897
subtest 'add_tt_filters' => sub {
898
    plan tests => 1;
899
    my $code   = "TEST";
900
    my $module = "TEST";
901
902
    my $patron = $builder->build_object(
903
        {
904
            class => 'Koha::Patrons',
905
            value => { surname => "with_punctuation_" }
906
        }
907
    );
908
    my $biblio = $builder->build_object(
909
        { class => 'Koha::Biblios', value => { title => "with_punctuation_" } }
910
    );
911
    my $biblioitem = $builder->build_object(
912
        {
913
            class => 'Koha::Biblioitems',
914
            value => {
915
                biblionumber => $biblio->biblionumber,
916
                isbn         => "with_punctuation_"
917
            }
918
        }
919
    );
920
921
    my $template = q|patron=[% borrower.surname %];biblio=[% biblio.title %];biblioitems=[% biblioitem.isbn %]|;
922
    reset_template( { template => $template, code => $code, module => $module } );
923
    my $letter = GetPreparedLetter(
924
        module      => $module,
925
        letter_code => $code,
926
        tables      => {
927
            borrowers   => $patron->borrowernumber,
928
            biblio      => $biblio->biblionumber,
929
            biblioitems => $biblioitem->biblioitemnumber
930
        }
931
    );
932
    my $expected_letter = q|patron=with_punctuation_;biblio=with_punctuation;biblioitems=with_punctuation|;
933
    is( $letter->{content}, $expected_letter, "Pre-processing should call TT plugin to remove punctuation if table is biblio or biblioitems");
934
};
935
936
897
sub reset_template {
937
sub reset_template {
898
    my ( $params ) = @_;
938
    my ( $params ) = @_;
899
    my $template   = $params->{template};
939
    my $template   = $params->{template};
900
- 

Return to bug 19578