Completed
Push — master ( 36bbbe...f30a93 )
by Tim
02:07
created

LanguageInformationViewHelper   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 0
loc 48
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A initializeArguments() 0 5 1
A render() 0 24 3
1
<?php
2
3
declare(strict_types=1);
4
/**
5
 * LanguageInformationViewHelper.
6
 */
7
8
namespace HDNET\Calendarize\ViewHelpers;
9
10
use TYPO3\CMS\Backend\Configuration\TranslationConfigurationProvider;
11
use TYPO3\CMS\Core\Imaging\Icon;
12
use TYPO3\CMS\Core\Imaging\IconFactory;
13
use TYPO3\CMS\Core\Utility\GeneralUtility;
14
15
/**
16
 * LanguageInformationViewHelper.
17
 */
18
class LanguageInformationViewHelper extends AbstractViewHelper
19
{
20
    /**
21
     * Flags.
22
     *
23
     * @var array
24
     */
25
    protected static $flags = [];
26
27
    /**
28
     * Init arguments.
29
     */
30
    public function initializeArguments()
31
    {
32
        parent::initializeArguments();
33
        $this->registerArgument('languageUid', 'int', 'Language UID', true);
34
    }
35
36
    /**
37
     * Render.
38
     *
39
     * @return string
40
     */
41
    public function render()
42
    {
43
        $langUid = (int) $this->arguments['languageUid'];
44
        if (\array_key_exists($langUid, self::$flags)) {
45
            return self::$flags[$langUid];
46
        }
47
48
        $translationTools = GeneralUtility::makeInstance(TranslationConfigurationProvider::class);
49
        $sysLanguages = $translationTools->getSystemLanguages();
50
51
        $iconFactory = GeneralUtility::makeInstance(IconFactory::class);
52
53
        $out = '';
54
        $title = \htmlspecialchars($sysLanguages[$langUid]['title']);
55
        if ($sysLanguages[$langUid]['flagIcon']) {
56
            $out .= '<span title="' . $title . '">' . $iconFactory->getIcon($sysLanguages[$langUid]['flagIcon'], Icon::SIZE_SMALL)->render() . '</span>';
57
            $out .= '&nbsp;';
58
        }
59
        $out .= $title;
60
61
        self::$flags[$this->arguments['languageUid']] = (string) $out;
62
63
        return $out;
64
    }
65
}
66