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

TYPO3-Headless / headless / 9887449051

11 Jul 2024 07:40AM UTC coverage: 65.718% (-0.1%) from 65.849%
9887449051

Pull #748

github

web-flow
Merge 8ca0df7df into 44ffec997
Pull Request #748: [FEATURE] Allow return only one element in CONTENT_JSON

0 of 3 new or added lines in 1 file covered. (0.0%)

993 of 1511 relevant lines covered (65.72%)

2.79 hits per line

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

0.0
/Classes/DataProcessing/RootSiteProcessing/SiteSchema.php
1
<?php
2

3
/*
4
 * This file is part of the "headless" Extension for TYPO3 CMS.
5
 *
6
 * For the full copyright and license information, please read the
7
 * LICENSE.md file that was distributed with this source code.
8
 */
9

10
declare(strict_types=1);
11

12
namespace FriendsOfTYPO3\Headless\DataProcessing\RootSiteProcessing;
13

14
use FriendsOfTYPO3\Headless\Utility\HeadlessFrontendUrlInterface;
15
use FriendsOfTYPO3\Headless\Utility\UrlUtility;
16
use TYPO3\CMS\Core\Utility\GeneralUtility;
17
use TYPO3\CMS\Frontend\ContentObject\ContentDataProcessor;
18
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
19

20
use function is_array;
21
use function trim;
22

23
class SiteSchema implements SiteSchemaInterface
24
{
25
    private HeadlessFrontendUrlInterface $urlUtitlity;
26
    private ContentDataProcessor $contentDataProcessor;
27

28
    public function __construct(
29
        HeadlessFrontendUrlInterface $urlUtitlity = null,
30
        ContentDataProcessor $contentObjectRenderer = null
31
    ) {
32
        $this->urlUtitlity = $urlUtitlity ?? GeneralUtility::makeInstance(UrlUtility::class);
×
33
        $this->contentDataProcessor = $contentObjectRenderer ??
×
34
            GeneralUtility::makeInstance(ContentDataProcessor::class);
×
35
    }
36

37
    /**
38
     * @param array<string, mixed> $options
39
     * @return array<int, array<string, mixed>>
40
     */
41
    public function process(SiteProviderInterface $provider, array $options = []): array
42
    {
43
        $processorConfiguration = $options['processorConfiguration'] ?? [];
×
44
        $siteUid = (int)($options['siteUid'] ?? 0);
×
45
        $titleField = $processorConfiguration['titleField'] ?? 'title';
×
46

47
        if (trim($titleField) === '') {
×
48
            $titleField = 'title';
×
49
        }
50

51
        $cObj = $options['cObj'] ?? GeneralUtility::makeInstance(ContentObjectRenderer::class);
×
52
        $result = [];
×
53
        $pages = $provider->getPages();
×
54

55
        foreach ($provider->getSites() as $site) {
×
56
            $current = 0;
×
57
            $active = 0;
×
58
            $spacer = 0;
×
59
            $baseUrl = $site->getBase()->getScheme() . '://' . $site->getBase()->getHost();
×
60
            $url = $this->urlUtitlity->getFrontendUrlForPage($baseUrl, $site->getRootPageId());
×
61

62
            if ($provider->getCurrentRootPage() === $site) {
×
63
                $active = 1;
×
64
                if ($site->getRootPageId() === $siteUid) {
×
65
                    $current = 1;
×
66
                }
67
            }
68

69
            $pageInfo = $pages[$site->getRootPageId()];
×
70

71
            $page = [
×
72
                'title' => $pageInfo[$titleField],
×
73
                'link' => $url,
×
74
                'active' => $active,
×
75
                'current' => $current,
×
76
                'spacer' => $spacer,
×
77
            ];
×
78

79
            // process page if necessary
80
            if (isset($processorConfiguration['dataProcessing.']) &&
×
81
                is_array($processorConfiguration['dataProcessing.'])) {
×
82
                $page = $this->processAdditionalDataProcessors(
×
83
                    $page,
×
84
                    $cObj,
×
85
                    $processorConfiguration
×
86
                );
×
87
            }
88

89
            $result[] = $page;
×
90
        }
91

92
        return $result;
×
93
    }
94

95
    /**
96
     * Process additional data processors
97
     *
98
     * @param array<string, mixed> $page
99
     * @param ContentObjectRenderer $cObj
100
     * @param array<string, mixed> $processorConfiguration
101
     * @return array<string, mixed>
102
     */
103
    protected function processAdditionalDataProcessors(
104
        $page,
105
        ContentObjectRenderer $cObj,
106
        $processorConfiguration
107
    ): array {
108
        $cObj->start($page, 'pages');
×
109
        return $this->contentDataProcessor->process($cObj, $processorConfiguration, $page);
×
110
    }
111
}
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