From 656104360e1b9ee261ec2885a06fcdca75d9d961 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 5 May 2020 15:51:25 +0200 Subject: [PATCH] Bug 23166: Call the methods from the .inc MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We do not longer need the order variables to be passed from the controllers, we can call the methods on the biblio object instead. 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) If adopted I will move the plugin on a separate bug report to ease backport Signed-off-by: Joonas Kylmälä --- Koha/Template/Plugin/Context.pm | 47 ++++++++++++++++++++++ .../prog/en/includes/catalog-strings.inc | 8 +++- 2 files changed, 53 insertions(+), 2 deletions(-) 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; diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/catalog-strings.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/catalog-strings.inc index 3e77d6a998..78980c334e 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/catalog-strings.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/catalog-strings.inc @@ -1,3 +1,4 @@ +[% USE Context %]