Passed
Push — typo3-v13 ( affeeb...10553b )
by Torben
02:38
created

TemplateLayouts::getLanguageService()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
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\Hooks;
13
14
use TYPO3\CMS\Backend\Utility\BackendUtility;
0 ignored issues
show
Bug introduced by
The type TYPO3\CMS\Backend\Utility\BackendUtility was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
15
use TYPO3\CMS\Core\Localization\LanguageService;
16
17
/**
18
 * Hook for Template Layouts
19
 */
20
class TemplateLayouts
21
{
22
    /**
23
     * Itemsproc function to extend the selection of templateLayouts in the plugin
24
     */
25
    public function user_templateLayout(array &$config): void
26
    {
27
        $pid = (int)($config['flexParentDatabaseRow']['pid'] ?? 0);
28
        $templateLayouts = $this->getTemplateLayoutsFromTsConfig($pid);
29
        foreach ($templateLayouts as $index => $layout) {
30
            $additionalLayout = [
31
                $this->getLanguageService()->sL($layout),
32
                $index,
33
            ];
34
            $config['items'][] = $additionalLayout;
35
        }
36
    }
37
38
    /**
39
     * Get template layouts defined in TsConfig
40
     */
41
    protected function getTemplateLayoutsFromTsConfig(int $pageUid): array
42
    {
43
        $templateLayouts = [];
44
        $pagesTsConfig = BackendUtility::getPagesTSconfig($pageUid);
45
        if (isset($pagesTsConfig['tx_sfeventmgt.']['templateLayouts.']) &&
46
            is_array($pagesTsConfig['tx_sfeventmgt.']['templateLayouts.'])
47
        ) {
48
            $templateLayouts = $pagesTsConfig['tx_sfeventmgt.']['templateLayouts.'];
49
        }
50
51
        return $templateLayouts;
52
    }
53
54
    protected function getLanguageService(): LanguageService
55
    {
56
        return $GLOBALS['LANG'];
57
    }
58
}
59