• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

FluidTYPO3 / flux / 27757675993

18 Jun 2026 11:55AM UTC coverage: 89.162% (-3.5%) from 92.646%
27757675993

push

github

NamelessCoder
[TASK] Address last phpstan warnings

6228 of 6985 relevant lines covered (89.16%)

40.84 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

78.79
/Classes/Backend/PageLayoutDataProvider.php
1
<?php
2
namespace FluidTYPO3\Flux\Backend;
3

4
/*
5
 * This file is part of the FluidTYPO3/Flux project under GPLv2 or later.
6
 *
7
 * For the full copyright and license information, please read the
8
 * LICENSE.md file that was distributed with this source code.
9
 */
10

11
use FluidTYPO3\Flux\Enum\FormOption;
12
use FluidTYPO3\Flux\Form;
13
use FluidTYPO3\Flux\Proxy\SiteFinderProxy;
14
use FluidTYPO3\Flux\Service\PageService;
15
use FluidTYPO3\Flux\Utility\ExtensionNamingUtility;
16
use FluidTYPO3\Flux\Utility\MiscellaneousUtility;
17
use TYPO3\CMS\Core\Exception\SiteNotFoundException;
18
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
19
use TYPO3\CMS\Core\Utility\GeneralUtility;
20
use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
21

22
class PageLayoutDataProvider
23
{
24
    private ConfigurationManagerInterface $configurationManager;
25
    private PageService $pageService;
26
    private SiteFinderProxy $siteFinder;
27

28
    public function __construct(
29
        ConfigurationManagerInterface $configurationManager,
30
        PageService $pageService,
31
        SiteFinderProxy $siteFinder
32
    ) {
33
        $this->configurationManager = $configurationManager;
20✔
34
        $this->pageService = $pageService;
20✔
35
        $this->siteFinder = $siteFinder;
20✔
36
    }
37

38
    public function addItems(array $parameters): array
39
    {
40
        $typoScript = $this->configurationManager->getConfiguration(
20✔
41
            ConfigurationManagerInterface::CONFIGURATION_TYPE_FULL_TYPOSCRIPT
20✔
42
        );
20✔
43
        $settings = GeneralUtility::removeDotsFromTS((array) ($typoScript['plugin.']['tx_flux.'] ?? []));
20✔
44
        if (isset($settings['siteRootInheritance'])) {
20✔
45
            $hideInheritFieldSiteRoot = 1 > $settings['siteRootInheritance'];
×
46
        } else {
47
            $hideInheritFieldSiteRoot = false;
20✔
48
        }
49
        $pageIsSiteRoot = (bool) ($parameters['row']['is_siteroot'] ?? false);
20✔
50
        $forceDisplayInheritSiteRoot = 'tx_fed_page_controller_action_sub' === ($parameters['field'] ?? null)
20✔
51
            && !$hideInheritFieldSiteRoot;
20✔
52
        $forceHideInherit = (0 === (int) ($parameters['row']['pid'] ?? 0));
20✔
53
        if (!$forceHideInherit) {
20✔
54
            if (!$pageIsSiteRoot || $forceDisplayInheritSiteRoot || !$hideInheritFieldSiteRoot) {
8✔
55
                $parameters['items'][] = [
8✔
56
                    'LLL:EXT:flux/Resources/Private/Language/locallang.xlf:pages.tx_fed_page_controller_action.default',
8✔
57
                    '',
8✔
58
                    'actions-move-down'
8✔
59
                ];
8✔
60
            }
61
        }
62

63
        $allowedTemplates = [];
20✔
64
        $pageUid = (int) ($parameters['row']['uid'] ?? 0);
20✔
65
        if ($pageUid > 0) {
20✔
66
            try {
67
                $site = $this->siteFinder->getSiteByPageId($pageUid);
×
68
                $siteConfiguration = $site->getConfiguration();
×
69
                if (is_array($siteConfiguration['flux_page_templates'] ?? null)) {
×
70
                    $allowedTemplates = $siteConfiguration['flux_page_templates'];
×
71
                } else {
72
                    $allowedTemplates = GeneralUtility::trimExplode(
×
73
                        ',',
×
74
                        $siteConfiguration['flux_page_templates'] ?? '',
×
75
                        true
×
76
                    );
×
77
                }
78
            } catch (SiteNotFoundException $exception) {
×
79
                $allowedTemplates = [];
×
80
            }
81
        }
82

83
        $availableTemplates = $this->pageService->getAvailablePageTemplateFiles();
20✔
84
        foreach ($availableTemplates as $extension => $group) {
20✔
85
            $parameters['items'] = array_merge(
20✔
86
                $parameters['items'],
20✔
87
                $this->renderOptions($extension, $group, $parameters, $allowedTemplates)
20✔
88
            );
20✔
89
        }
90

91
        return $parameters;
20✔
92
    }
93

94
    protected function renderOptions(string $extension, array $group, array $parameters, array $allowedTemplates): array
95
    {
96
        $options = [];
20✔
97
        if (!empty($group)) {
20✔
98
            $extensionKey = ExtensionNamingUtility::getExtensionKey($extension);
20✔
99
            $groupTitle = $this->getGroupTitle($extensionKey);
20✔
100

101
            $templateOptions = [];
20✔
102
            foreach ($group as $form) {
20✔
103
                $optionArray = $this->renderOption($form, $parameters);
20✔
104
                if (!empty($allowedTemplates) && !in_array($optionArray[1], $allowedTemplates)) {
20✔
105
                    continue;
×
106
                }
107
                $templateOptions[] = $optionArray;
20✔
108
            }
109
            if (!empty($templateOptions)) {
20✔
110
                $options = array_merge($options, [[$groupTitle, '--div--']], $templateOptions);
20✔
111
            }
112
        }
113
        return $options;
20✔
114
    }
115

116
    protected function renderOption(Form $form, array $parameters): array
117
    {
118
        $extension = $form->getExtensionName();
20✔
119
        $thumbnail = MiscellaneousUtility::getIconForTemplate($form);
20✔
120
        if ($thumbnail) {
20✔
121
            $thumbnail = ltrim($thumbnail, '/');
×
122
        }
123
        /** @var string|null $template */
124
        $template = $form->getOption(FormOption::TEMPLATE_FILE_RELATIVE);
20✔
125
        if ($template === null) {
20✔
126
            return [];
12✔
127
        }
128
        $label = $form->getLabel();
8✔
129
        $optionValue = $extension . '->' . lcfirst($template);
8✔
130
        $option = [$label, $optionValue, $thumbnail];
8✔
131
        return $option;
8✔
132
    }
133

134
    /**
135
     * @codeCoverageIgnore
136
     */
137
    protected function getGroupTitle(string $extensionKey): string
138
    {
139
        if (!$this->isExtensionLoaded($extensionKey)) {
140
            $groupTitle = ucfirst($extensionKey);
141
        } else {
142
            $emConfigFile = ExtensionManagementUtility::extPath($extensionKey, 'ext_emconf.php');
143
            $_EXTKEY = $extensionKey;
144
            require $emConfigFile;
145
            $groupTitle = reset($EM_CONF)['title'];
146
        }
147
        return $groupTitle;
148
    }
149

150
    /**
151
     * @codeCoverageIgnore
152
     */
153
    protected function isExtensionLoaded(string $extensionKey): bool
154
    {
155
        return ExtensionManagementUtility::isLoaded($extensionKey);
156
    }
157
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc