@@ -, +, @@ notices --- C4/Letters.pm | 31 ++++++++++++++---------- t/db_dependent/Letters/TemplateToolkit.t | 14 ++++++++++- 2 files changed, 31 insertions(+), 14 deletions(-) --- a/C4/Letters.pm +++ a/C4/Letters.pm @@ -638,12 +638,13 @@ sub GetPreparedLetter { $letter->{'content-type'} = 'text/html; charset="UTF-8"' if $letter->{is_html}; } + my $objects = $params{objects} || {}; my $tables = $params{tables} || {}; my $substitute = $params{substitute} || {}; my $loops = $params{loops} || {}; # loops is not supported for historical notices syntax my $repeat = $params{repeat}; - %$tables || %$substitute || $repeat || %$loops - or carp( "ERROR: nothing to substitute - both 'tables', 'loops' and 'substitute' are empty" ), + %$tables || %$substitute || $repeat || %$loops || %$objects + or carp( "ERROR: nothing to substitute - all of 'objects', 'tables', 'loops' and 'substitute' are empty" ), return; my $want_librarian = $params{want_librarian}; @@ -718,20 +719,23 @@ sub GetPreparedLetter { $letter->{content} = _process_tt( { - content => $letter->{content}, - tables => $tables, - loops => $loops, + content => $letter->{content}, + lang => $lang, + loops => $loops, + objects => $objects, substitute => $substitute, - lang => $lang + tables => $tables, } ); $letter->{title} = _process_tt( { - content => $letter->{title}, - tables => $tables, - loops => $loops, + content => $letter->{title}, + lang => $lang, + loops => $loops, + objects => $objects, substitute => $substitute, + tables => $tables, } ); @@ -1616,9 +1620,10 @@ sub _set_message_status { sub _process_tt { my ( $params ) = @_; - my $content = $params->{content}; - my $tables = $params->{tables}; - my $loops = $params->{loops}; + my $content = $params->{content}; + my $tables = $params->{tables}; + my $loops = $params->{loops}; + my $objects = $params->{objects}; my $substitute = $params->{substitute} || {}; my $lang = defined($params->{lang}) && $params->{lang} ne 'default' ? $params->{lang} : 'en'; my ($theme, $availablethemes); @@ -1645,7 +1650,7 @@ sub _process_tt { } ) or die Template->error(); - my $tt_params = { %{ _get_tt_params( $tables ) }, %{ _get_tt_params( $loops, 'is_a_loop' ) }, %$substitute }; + my $tt_params = { %{ _get_tt_params( $tables ) }, %{ _get_tt_params( $loops, 'is_a_loop' ) }, %$substitute, %$objects }; $content = add_tt_filters( $content ); $content = qq|[% USE KohaDates %][% USE Remove_MARC_punctuation %]$content|; --- a/t/db_dependent/Letters/TemplateToolkit.t +++ a/t/db_dependent/Letters/TemplateToolkit.t @@ -19,7 +19,7 @@ # along with Koha; if not, see . use Modern::Perl; -use Test::More tests => 28; +use Test::More tests => 29; use Test::MockModule; use Test::Warn; @@ -44,6 +44,7 @@ use Koha::Serial; use Koha::Subscription; use Koha::Suggestion; use Koha::Checkout; +use Koha::Patrons; use Koha::Notice::Messages; use Koha::Notice::Templates; use Koha::Patron::Modification; @@ -139,6 +140,17 @@ $prepared_letter = GetPreparedLetter( is( $prepared_letter->{content}, $patron->{borrowernumber}, 'Patron object used correctly with arrayref for content' ); is( $prepared_letter->{title}, $patron->{firstname}, 'Patron object used correctly with arrayref for title' ); +$prepared_letter = GetPreparedLetter( + ( + module => 'test', + letter_code => 'TEST_PATRON', + objects => { + borrower => scalar Koha::Patrons->find( $patron->{borrowernumber} ), + }, + ) +); +is( $prepared_letter->{content}, $patron->{borrowernumber}, 'Patron object used correctly as object' ); + $sth->execute( "TEST_BIBLIO", "[% biblio.title %]", "[% biblio.id %]" ); $prepared_letter = GetPreparedLetter( ( --