Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
CRAP
0.00% covered (danger)
0.00%
0 / 1
TransEscAttr
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
 __invoke
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3/**
4 * Translate + escape view helper for HTML attributes
5 *
6 * PHP version 8
7 *
8 * Copyright (C) Villanova University 2010.
9 * Copyright (C) The National Library of Finland 2020.
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2,
13 * as published by the Free Software Foundation.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
23 *
24 * @category VuFind
25 * @package  View_Helpers
26 * @author   Demian Katz <demian.katz@villanova.edu>
27 * @author   Ere Maijala <ere.maijala@helsinki.fi>
28 * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
29 * @link     https://vufind.org/wiki/development Wiki
30 */
31
32namespace VuFind\View\Helper\Root;
33
34use Laminas\View\Helper\AbstractHelper;
35
36/**
37 * Translate + escape view helper for HTML attributes
38 *
39 * @category VuFind
40 * @package  View_Helpers
41 * @author   Demian Katz <demian.katz@villanova.edu>
42 * @author   Ere Maijala <ere.maijala@helsinki.fi>
43 * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
44 * @link     https://vufind.org/wiki/development Wiki
45 */
46class TransEscAttr extends AbstractHelper
47{
48    /**
49     * Translate and escape a string for an HTML attribute
50     *
51     * @param string|object|array $str             String to translate or an array of text
52     *                                             domain and string to translate
53     * @param array               $tokens          Tokens to inject into the translated string
54     * @param string              $default         Default value to use if no translation is
55     *                                             found (null for no default).
56     * @param bool                $useIcuFormatter Should we use an ICU message formatter instead
57     * of the default behavior?
58     * @param string[]            $fallbackDomains Text domains to check if no match is found in
59     * the domain specified in $target
60     *
61     * @return string
62     */
63    public function __invoke(
64        $str,
65        $tokens = [],
66        $default = null,
67        $useIcuFormatter = false,
68        $fallbackDomains = []
69    ) {
70        $escaper = $this->getView()->plugin('escapeHtmlAttr');
71        $translator = $this->getView()->plugin('translate');
72        return $escaper($translator($str, $tokens, $default, $useIcuFormatter, $fallbackDomains));
73    }
74}