Passed
Push — typo3_11 ( a70f5c...526d7d )
by Torben
50:31
created

TitleViewHelper::getTypoScriptFrontendController()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Extension "sf_event_mgt" for TYPO3 CMS.
7
 *
8
 * For the full copyright and license information, please read the
9
 * LICENSE.txt file that was distributed with this source code.
10
 */
11
12
namespace DERHANSEN\SfEventMgt\ViewHelpers;
13
14
use DERHANSEN\SfEventMgt\PageTitle\EventPageTitleProvider;
15
use TYPO3\CMS\Core\Utility\GeneralUtility;
16
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
17
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
18
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
19
use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
20
21
/**
22
 * ViewHelper to render the page title and indexed search title
23
 */
24
class TitleViewHelper extends AbstractViewHelper
25
{
26
    use CompileWithRenderStatic;
27
28
    /**
29
     * Initialize arguments
30
     */
31
    public function initializeArguments()
32
    {
33
        parent::initializeArguments();
34
        $this->registerArgument('pageTitle', 'String', 'The page title');
35
        $this->registerArgument(
36
            'indexedDocTitle',
37
            'string',
38
            'The title for the event in indexed search result',
39
            false
40
        );
41
    }
42
43
    /**
44
     * @param array $arguments
45
     * @param \Closure $renderChildrenClosure
46
     * @param RenderingContextInterface $renderingContext
47
     */
48
    public static function renderStatic(
49
        array $arguments,
50
        \Closure $renderChildrenClosure,
51
        RenderingContextInterface $renderingContext
52
    ) {
53
        $pageTitle = $arguments['pageTitle'] ?? '';
54
        $indexedDocTitle = $arguments['indexedDocTitle'] ?? $pageTitle;
55
        if ($pageTitle !== '') {
56
            GeneralUtility::makeInstance(EventPageTitleProvider::class)->setTitle($pageTitle);
57
        }
58
        if (self::getTypoScriptFrontendController() && $indexedDocTitle !== '') {
59
            self::getTypoScriptFrontendController()->indexedDocTitle = $indexedDocTitle;
60
        }
61
    }
62
63
    protected static function getTypoScriptFrontendController(): ?TypoScriptFrontendController
64
    {
65
        return $GLOBALS['TSFE'] ?? null;
66
    }
67
}
68