Skip to content
Snippets Groups Projects
Commit 051179ce authored by Aspectis's avatar Aspectis Committed by Dorian Merz
Browse files

refs #18868 [fid_bbi] add icons to alerts

parent 3bdb7ec4
No related merge requests found
<?php
/**
* Flash message view helper
*
* PHP version 7
*
* Copyright (C) Leipzig University Library 2020.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* This program 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 this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category VuFind
* @package View_Helpers
* @author Heike Reinken <reinken@ub.uni-leipzig.de>
* @author Tobias Schäfer <ts@aspectis.net>
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link https://vufind.org/wiki/development Wiki
*/
namespace fid_bbi\View\Helper\Root;
/**
* Flash message view helper
*
* @category VuFind
* @package View_Helpers
* @author Heike Reinken <reinken@ub.uni-leipzig.de>
* @author Tobias Schäfer <ts@aspectis.net>
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link https://vufind.org/wiki/development Wiki
*/
class Flashmessages extends \VuFind\View\Helper\Bootstrap3\Flashmessages
{
/**
* Generate flash message <p>'s with appropriate classes based on message type.
* This is basically a copy of the finc method but adds BBI-specific icons
*
* @return string $html
*/
public function __invoke()
{
$html = '';
$namespaces = ['error', 'info', 'success'];
$icons = [
'error' => 'error',
'info' => 'info',
'success' => 'checkmark',
];
foreach ($namespaces as $ns) {
$messages = array_merge(
$this->fm->getMessages($ns),
$this->fm->getCurrentMessages($ns)
);
foreach (array_unique($messages, SORT_REGULAR) as $msg) {
$html .= '<p class="' . $this->getClassForNamespace($ns) . '"';
if (isset($msg['dataset'])) {
foreach ($msg['dataset'] as $attr => $value) {
$html .= ' data-' . $attr . '="' . htmlspecialchars($value) . '"';
}
}
$html .= '>';
// BBI-specific
// Add icon based on namespace
$iconHelper = $this->getView()->plugin('icon');
$html .= $iconHelper("small/{$icons[$ns]}");
// Advanced form
if (is_array($msg)) {
// Use a different translate helper depending on whether or not we're in HTML mode.
if (!isset($msg['translate']) || $msg['translate']) {
$helper = (isset($msg['html']) && $msg['html'])
? 'translate'
: 'transEsc';
} else {
$helper = (isset($msg['html']) && $msg['html'])
? false
: 'escapeHtml';
}
$helper = $helper
? $this->getView()->plugin($helper)
: false;
$tokens = $msg['tokens'] ?? [];
$default = $msg['default'] ?? null;
$html .= $helper
? $helper($msg['msg'], $tokens, $default)
: $msg['msg'];
} else {
// Basic default string
$transEsc = $this->getView()->plugin('transEsc');
$html .= $transEsc($msg);
}
$html .= '</p>';
}
$this->fm->clearMessages($ns);
$this->fm->clearCurrentMessages($ns);
}
return $html;
}
}
...@@ -12,10 +12,13 @@ return [ ...@@ -12,10 +12,13 @@ return [
], ],
'helpers' => array( 'helpers' => array(
'aliases' => [ 'aliases' => [
'flashmessages' => 'fid_bbi\View\Helper\Root\Flashmessages',
'icon' => 'fid_bbi\View\Helper\Root\Icon', 'icon' => 'fid_bbi\View\Helper\Root\Icon',
'record' => 'fid_bbi\View\Helper\Root\Record', 'record' => 'fid_bbi\View\Helper\Root\Record',
], ],
'factories' => [ 'factories' => [
'fid_bbi\View\Helper\Root\Flashmessages' =>
'VuFind\View\Helper\Root\FlashmessagesFactory',
'fid_bbi\View\Helper\Root\Icon' => 'fid_bbi\View\Helper\Root\Icon' =>
'fid_bbi\View\Helper\Root\Icon', 'fid_bbi\View\Helper\Root\Icon',
'fid_bbi\View\Helper\Root\Record' => 'fid_bbi\View\Helper\Root\Record' =>
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment