From eb0cdb5f9278b50e34f3d599642e629b66413993 Mon Sep 17 00:00:00 2001 From: Owen Leonard Date: Wed, 21 Jan 2026 09:19:08 -0500 Subject: [PATCH] Bug 41674: Add template plugin for linking to system preferences based on user permission This patch adds a new template plugin, LinkPref, for displaying system preference names as links depending on the logged-in user's permission. Syntax: [% "SYSTEM_PREFERENCE_NAME" | html | $LinkPref %] For a user with 'CAN_user_parameters_manage_sysprefs' permission it outputs: SYSTEM_PREFERENCE_NAME For a user without permission it outputs: SYSTEM_PREFERENCE_NAME Sponsored-by: Athens County Public Libraries --- Koha/Template/Plugin/LinkPref.pm | 69 ++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 Koha/Template/Plugin/LinkPref.pm diff --git a/Koha/Template/Plugin/LinkPref.pm b/Koha/Template/Plugin/LinkPref.pm new file mode 100644 index 00000000000..a53dbda6005 --- /dev/null +++ b/Koha/Template/Plugin/LinkPref.pm @@ -0,0 +1,69 @@ +package Koha::Template::Plugin::LinkPref; + +# Copyright Athens County Public Libraries 2026 +# Author: Owen Leonard + +# 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 Koha::Patrons; + +use Template::Plugin::Filter; +use base qw( Template::Plugin::Filter ); +our $DYNAMIC = 1; + +sub filter { + my ( $self, $text ) = @_; + return "" unless $text; + my $span; + + if ( $self->{_CONTEXT}->stash->{'CAN_user_parameters_manage_sysprefs'} ) { + $span .= ''; + $span .= $text; + $span .= ''; + } else { + $span .= ''; + $span .= $text; + $span .= ''; + } + + return $span; +} + +1; + +=head1 NAME + +Koha::Template::Plugin::LinkPref - TT plugin for wrapping a system preference name in a link to that preference if the user has permission + +=head1 SYNOPSIS + +[% USE LinkPref %] + +[% "SYSTEM_PREFERENCE_NAME" | html | $LinkPref %] + +This filter scrubs HTML using profiles predefined in C4::Scrubber + +=head1 METHODS + +=head2 filter + +Returns the system preference variable name as an HTML link or plain text based on the logged-in user's permissions + +=cut -- 2.39.5