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

FluidTYPO3 / flux / 14774311267

01 May 2025 11:00AM UTC coverage: 93.246% (+0.3%) from 92.9%
14774311267

push

github

NamelessCoder
[TER] 11.0.0

7083 of 7596 relevant lines covered (93.25%)

66.31 hits per line

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

76.47
/Classes/Backend/PageLayoutDataProvider.php
1
<?php
2
declare(strict_types=1);
3
namespace FluidTYPO3\Flux\Backend;
4

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

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

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

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

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

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

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

92
        return $parameters;
35✔
93
    }
94

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

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

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

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

153
    /**
154
     * @codeCoverageIgnore
155
     */
156
    protected function isExtensionLoaded(string $extensionKey): bool
157
    {
158
        return ExtensionManagementUtility::isLoaded($extensionKey);
159
    }
160
}
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