Passed
Pull Request — master (#1348)
by Timo
32:03
created

TranslateViewHelper   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 1
dl 0
loc 44
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A renderStatic() 0 13 4
A replaceTranslationPrefixesWithAtWithStringMarker() 0 7 2
1
<?php
2
namespace ApacheSolrForTypo3\Solr\ViewHelpers;
3
4
/*
5
 * This file is part of the TYPO3 CMS project.
6
 *
7
 * It is free software; you can redistribute it and/or modify it under
8
 * the terms of the GNU General Public License, either version 2
9
 * of the License, or any later version.
10
 *
11
 * For the full copyright and license information, please read the
12
 * LICENSE.txt file that was distributed with this source code.
13
 *
14
 * The TYPO3 project - inspiring people to share!
15
 */
16
17
use TYPO3\CMS\Fluid\ViewHelpers\TranslateViewHelper as CoreTranslateViewHelper;
18
use TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface;
19
20
/**
21
 * Class TranslateViewHelper
22
 *
23
 * @author Frans Saris <[email protected]>
24
 * @author Timo Hund <[email protected]>
25
 * @package ApacheSolrForTypo3\Solr\ViewHelpers
26
 */
27
class TranslateViewHelper extends CoreTranslateViewHelper
28
{
29
    /**
30
     * @var bool
31
     */
32
    protected $escapeChildren = true;
33
34
    /**
35
     * @var bool
36
     */
37
    protected $escapeOutput = false;
38
39
    /**
40
     * @param array $arguments
41
     * @param \Closure $renderChildrenClosure
42
     * @param RenderingContextInterface $renderingContext
43
     * @return string
44
     */
45
    public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
46
    {
47
        $arguments['extensionName'] = $arguments['extensionName'] === null ? 'Solr' : $arguments['extensionName'];
48
        $result = parent::renderStatic($arguments, $renderChildrenClosure, $renderingContext);
49
50
        $result = self::replaceTranslationPrefixesWithAtWithStringMarker($result);
51
        if (trim($result) === '') {
52
            $result = $arguments['default'] !== null ? $arguments['default'] : $renderChildrenClosure();
53
        }
54
55
        $result = vsprintf($result, $arguments['arguments']);
56
        return $result;
57
    }
58
59
    /**
60
     * @param $result
61
     * @return mixed
62
     */
63
    protected static function replaceTranslationPrefixesWithAtWithStringMarker($result)
64
    {
65
        if (strpos($result, '@') !== false) {
66
            $result = preg_replace('~\"?@[a-zA-Z]*\"?~', '%s', $result);
67
        }
68
        return $result;
69
    }
70
}
71