From 9346274c72732d8e3fd37e674df83a7e6aaa0677 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 24 Aug 2020 09:58:15 +0200 Subject: [PATCH] Bug 26139: Koha::Template::Plugin::Context There is something wrong with our ->search method and TT behaviours, it is hard to retrieve object list in a scalar context. If [% objects.method.count %] is called, objects.method will get the first object of the list and count will explode (Koha::Object->count does not exist) We need to force the call in a scalar context to retrieve an iterator and prevent to fetch all the objects (we could have called all then size, but it's not efficient) --- Koha/Template/Plugin/Context.pm | 47 +++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 Koha/Template/Plugin/Context.pm diff --git a/Koha/Template/Plugin/Context.pm b/Koha/Template/Plugin/Context.pm new file mode 100644 index 0000000000..03c024b609 --- /dev/null +++ b/Koha/Template/Plugin/Context.pm @@ -0,0 +1,47 @@ +package Koha::Template::Plugin::Context; + +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# Koha is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Koha; if not, see . + +use Modern::Perl; + +use base qw( Template::Plugin ); + +use C4::Context; + +=head1 NAME + +Koha::Template::Plugin::Scalar - Return object set in scalar context + +=head1 SYNOPSIS + +If you need to force scalar context when calling a method on a object set. +Especially useful to call ->search + +=cut + +=head1 API + +=head2 Class Methods + +=cut + +sub Scalar { + my ( $self, $set, $method ) = @_; + $set = $set->$method; + return $set; +} + +1; -- 2.20.1