Commit 7d69ea1a authored by Philip Liebel's avatar Philip Liebel

remove IconUtility, use TYPO3\CMS\Core\Imaging\IconFactory instead

parent d6bdbbe8
2018-07-23 Philip Liebel <philip.liebel@cabag.ch>
* version 8.7.2
* remove IconUtility, use TYPO3\CMS\Core\Imaging\IconFactory instead
2018-07-09 Beat Haenger <beat.hanger@cabag.ch>
* version 8.7.1
* adds info on how to install 8.7 version in Readme.me
......
<?php
namespace Cabag\CabagLanglink\Utility;
use TYPO3\CMS\Core\Utility\PathUtility;
use TYPO3\CMS\Backend\Form\Utility\FormEngineUtility;
/***************************************************************
* Copyright notice
*
* Copyright (c) 2018, Philip Liebel <philip.liebel@cabag.ch>
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project 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 2 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script 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.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
class IconUtility {
/**
*
* @param string $lang
* @param string $style
* @return string
*/
public static function flagImg ($lang, $style= '') {
$flagIconsPath = PATH_typo3 . 'sysext/core/Resources/Public/Icons/Flags/PNG/';
if(!$lang) {
$lang = 'de';
}
$absoluteFilePath = $flagIconsPath . strtoupper($lang) . '.png';
return ' src="' . htmlspecialchars(PathUtility::getAbsoluteWebPath($absoluteFilePath)) . '"'
. ' alt="" title="" ' . $style
. ' ';
}
}
<?php
namespace Cabag\CabagLanglink\Utility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Imaging\IconFactory;
use TYPO3\CMS\Core\Imaging\Icon;
/***************************************************************
* Copyright notice
*
......@@ -31,8 +35,14 @@ use TYPO3\CMS\Backend\Utility\BackendUtility;
* @author Sonja Scholz <ss@cabag.ch>
* @package TYPO3
*/
final class LanglinkBrowseLinksUtility
class LanglinkBrowseLinksUtility
{
/**
*
* @var TYPO3\CMS\Core\Imaging\IconFactory
*/
protected static $iconFactory;
/**
* get the flag HTML for the xclasses
*
......@@ -80,14 +90,8 @@ final class LanglinkBrowseLinksUtility
$classAttr = '';
// create link to the default language
$defaultLangLink = '
<span class="list-tree-title">
<a href="'
. self::getHref($uid, $langRecord['sys_language_uid']) .'" style="' . $internalStyle . '" class="t3js-pageLink ' . trim($classAttr) . '" >'
. '<img'.IconUtility::flagImg($defaultFlag, 'width="20" height="12"').' alt="" />
</a>
</span>';
$defaultLangLink = self::getLangLink($uid, $langRecord['sys_language_uid'], $defaultFlag, $classAttr, $internalStyle);
// create link to other languages
if (is_array($listOfLangRecords) && !empty($listOfLangRecords)) {
$localizedLangLinkData = array();
......@@ -100,13 +104,7 @@ final class LanglinkBrowseLinksUtility
// version 4.5.0 only saves 'gb' for 'gb.gif'
//$langRecord['lang_flag'] .= '.svg';
}
$localizedLangLinkData['sys_language_uid_' . $langRecord['sys_language_uid']] = '
<span class="list-tree-title">
<a href="'. self::getHref($uid, $langRecord['sys_language_uid']) . '" style="' . $internalStyle . '" class="t3js-pageLink ' . trim($classAttr) . '"'
. ' data-l="' . $langRecord['sys_language_uid'] . '" >'
. '<img'. IconUtility::flagImg($langRecord['lang_flag'], 'width="20" height="12"').' alt="" />
</a>
</span>';
$localizedLangLinkData['sys_language_uid_' . $langRecord['sys_language_uid']] = self::getLangLink($uid, $langRecord['sys_language_uid'], $langRecord['lang_flag'], $classAttr, $internalStyle);
}
// display lang links ordered by sys_language_uid
krsort($localizedLangLinkData);
......@@ -122,6 +120,46 @@ final class LanglinkBrowseLinksUtility
return $langLinks;
}
/**
*
* @return TYPO3\CMS\Core\Imaging\IconFactory
*/
protected static function getIconFactory() {
if(!self::$iconFactory) {
self::$iconFactory = GeneralUtility::makeInstance(IconFactory::class);
}
return self::$iconFactory;
}
/**
*
* @param string $lang - language identifier
* @return string
*/
protected static function getFlagIcon($lang) {
$icon = self::getIconFactory()->getIcon('flags-' . strtolower($lang), Icon::SIZE_SMALL);
return $icon->getMarkup();
}
/**
*
* @param int $uid
* @param int $sysLanguageUid
* @param string $lang
* @param string $classAttr
* @param string $internalStyle
* @return string
*/
protected static function getLangLink($uid, $sysLanguageUid = 0, $lang = '', $classAttr = '', $internalStyle = '') {
return '<span class="list-tree-title">
<a href="'
. self::getHref($uid, $sysLanguageUid) .'" style="' . $internalStyle . '" class="t3js-pageLink ' . trim($classAttr) . '" '
. ' data-l="' . $sysLanguageUid . '" >'
. self::getFlagIcon($lang)
. '</a>'
. '</span>';
}
/**
*
* @param int $pid
......
......@@ -21,7 +21,7 @@ $EM_CONF[$_EXTKEY] = array(
'createDirs' => '',
'clearCacheOnLoad' => 0,
'author_company' => '',
'version' => '8.7.1',
'version' => '8.7.2',
'constraints' =>
array(
'depends' =>
......
Markdown is supported
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