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

Yoast / Yoast-SEO-for-TYPO3 / 21916594510

11 Feb 2026 05:54PM UTC coverage: 10.09% (+8.8%) from 1.275%
21916594510

push

github

RinyVT
[FEATURE] Version 12.0.0, added v14 support, removed v11 support including php8.0 and php8.1, rewrote backend javascript functionality to typescript and webcomponents

28 of 550 new or added lines in 53 files covered. (5.09%)

33 existing lines in 21 files now uncovered.

268 of 2656 relevant lines covered (10.09%)

0.27 hits per line

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

0.0
/Classes/Service/SnippetPreview/SnippetPreviewRequestDataGenerator.php
1
<?php
2

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

10
declare(strict_types=1);
11

12
namespace YoastSeoForTypo3\YoastSeo\Service\SnippetPreview;
13

14
use TYPO3\CMS\Backend\Utility\BackendUtility;
15
use TYPO3\CMS\Core\Domain\Repository\PageRepository;
16
use TYPO3\CMS\Core\Utility\GeneralUtility;
17
use TYPO3\CMS\Frontend\Page\CacheHashCalculator;
18
use YoastSeoForTypo3\YoastSeo\Dto\RequestData;
19
use YoastSeoForTypo3\YoastSeo\Service\UrlService;
20

21
class SnippetPreviewRequestDataGenerator
22
{
23
    public function __construct(
24
        protected CacheHashCalculator $cacheHashCalculator,
25
        protected UrlService $urlService
NEW
26
    ) {}
×
27

28
    /**
29
     * @param array<string, mixed> $data
30
     */
31
    public function getRequestData(array $data): RequestData
32
    {
NEW
33
        $currentPageId = (int)$data['effectivePid'];
×
NEW
34
        $recordId = (int)$data['vanillaUid'];
×
NEW
35
        $tableName = $data['tableName'];
×
36

NEW
37
        $record = $this->getRecordArray($tableName, $recordId);
×
NEW
38
        $previewConfiguration = $this->getPreviewConfiguration($currentPageId, $tableName);
×
39

NEW
40
        $previewPageId = $this->getPreviewPageId($currentPageId, $previewConfiguration);
×
NEW
41
        $languageId = $this->resolveLanguageId($tableName, $record);
×
42

NEW
43
        $recordId = $this->resolveRecordIdForLanguageHandling(
×
NEW
44
            $tableName,
×
NEW
45
            $record,
×
NEW
46
            $previewConfiguration,
×
NEW
47
            $recordId,
×
NEW
48
            $previewPageId
×
NEW
49
        );
×
50

NEW
51
        $linkParameters = $this->buildLinkParameters($record, $recordId, $previewConfiguration);
×
52

NEW
53
        if (!empty($previewConfiguration['useCacheHash'])) {
×
NEW
54
            $this->addCacheHash($linkParameters, $previewPageId);
×
55
        }
56

NEW
57
        $additionalParams = GeneralUtility::implodeArrayForUrl('', $linkParameters, '', false, true);
×
58

NEW
59
        return new RequestData($previewPageId, $languageId, $additionalParams);
×
60
    }
61

62
    /**
63
     * @param array<string, mixed> $record
64
     */
65
    protected function resolveLanguageId(string $tableName, array $record): int
66
    {
NEW
67
        $languageField = $GLOBALS['TCA'][$tableName]['ctrl']['languageField'] ?? '';
×
NEW
68
        if ($languageField === '' || empty($record[$languageField])) {
×
NEW
69
            return 0;
×
70
        }
71

NEW
72
        return $record[$languageField] > -1 ? (int)$record[$languageField] : 0;
×
73
    }
74

75
    /**
76
     * @param array<string, mixed> $record
77
     * @param array<string, mixed> $config
78
     */
79
    protected function resolveRecordIdForLanguageHandling(
80
        string $tableName,
81
        array $record,
82
        array $config,
83
        int $recordId,
84
        int &$previewPageId
85
    ): int {
NEW
86
        $languageField = $GLOBALS['TCA'][$tableName]['ctrl']['languageField'] ?? '';
×
NEW
87
        if (!$languageField || empty($record[$languageField])) {
×
NEW
88
            return $recordId;
×
89
        }
90

NEW
91
        $pointerField = $GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField'] ?? '';
×
NEW
92
        if (!$pointerField || empty($record[$pointerField])) {
×
NEW
93
            return $recordId;
×
94
        }
95

96
        // Use parent record if configured
97
        if (
NEW
98
            isset($config['useDefaultLanguageRecord']) &&
×
NEW
99
            !$config['useDefaultLanguageRecord']
×
100
        ) {
NEW
101
            $recordId = (int)$record[$pointerField];
×
102
        }
103

104
        // Special case for pages
NEW
105
        if ($tableName === 'pages') {
×
NEW
106
            $previewPageId = (int)$record[$pointerField];
×
107
        }
108

NEW
109
        return $recordId;
×
110
    }
111

112
    /**
113
     * @param array<string, mixed> $record
114
     * @param array<string, mixed> $config
115
     * @return array<int|string, mixed>
116
     */
117
    protected function buildLinkParameters(array $record, int $recordId, array $config): array
118
    {
NEW
119
        $params = [];
×
120

NEW
121
        if (!empty($config['fieldToParameterMap.'])) {
×
NEW
122
            foreach ($config['fieldToParameterMap.'] as $field => $parameterName) {
×
NEW
123
                $value = $field === 'uid' ? $recordId : ($record[$field] ?? '');
×
NEW
124
                $params[$parameterName] = $value;
×
125
            }
126
        }
127

NEW
128
        if (!empty($config['additionalGetParameters.'])) {
×
NEW
129
            $additional = [];
×
NEW
130
            $this->parseAdditionalGetParameters($additional, $config['additionalGetParameters.']);
×
NEW
131
            $params = array_replace($params, $additional);
×
132
        }
133

NEW
134
        return $params;
×
135
    }
136

137
    /**
138
     * @param array<string, mixed> $params
139
     */
140
    protected function addCacheHash(array &$params, int $previewPageId): void
141
    {
NEW
142
        $queryString = GeneralUtility::implodeArrayForUrl(
×
NEW
143
            '',
×
NEW
144
            array_merge($params, ['id' => $previewPageId])
×
NEW
145
        );
×
146

NEW
147
        $cacheHashParams = $this->cacheHashCalculator->getRelevantParameters($queryString);
×
NEW
148
        $params['cHash'] = $this->cacheHashCalculator->calculateCacheHash($cacheHashParams);
×
149
    }
150

151
    /**
152
     * @param array<string, mixed> $previewConfiguration
153
     */
154
    protected function getPreviewPageId(int $currentPageId, array $previewConfiguration): int
155
    {
NEW
156
        $configured = (int)($previewConfiguration['previewPageId'] ?? 0);
×
NEW
157
        if ($configured > 0) {
×
NEW
158
            return $configured;
×
159
        }
160

NEW
161
        $rootLine = BackendUtility::BEgetRootLine($currentPageId);
×
NEW
162
        $currentPage = reset($rootLine);
×
163

NEW
164
        if ((int)$currentPage['doktype'] <= PageRepository::DOKTYPE_SPACER) {
×
NEW
165
            return $currentPageId;
×
166
        }
167

NEW
168
        foreach ($rootLine as $page) {
×
NEW
169
            if (!empty($page['is_siteroot'])) {
×
NEW
170
                return (int)$page['uid'];
×
171
            }
172
        }
173

NEW
174
        return $currentPageId;
×
175
    }
176

177
    /**
178
     * @return array<string, mixed>
179
     */
180
    protected function getRecordArray(string $tableName, int $recordId): array
181
    {
NEW
182
        return BackendUtility::getRecord($tableName, $recordId) ?? [];
×
183
    }
184

185
    /**
186
     * @return array<string, mixed>
187
     */
188
    protected function getPreviewConfiguration(int $currentPageId, string $tableName): array
189
    {
NEW
190
        $pageTsConfig = BackendUtility::getPagesTSconfig($currentPageId);
×
NEW
191
        return $pageTsConfig['TCEMAIN.']['preview.'][$tableName . '.'] ?? [];
×
192
    }
193

194
    /**
195
     * Migrates a set of (possibly nested) GET parameters in TypoScript syntax to a
196
     * plain array
197
     *
198
     * This basically removes the trailing dots of sub-array keys in TypoScript.
199
     * The result can be used to create a query string with
200
     * GeneralUtility::implodeArrayForUrl().
201
     *
202
     * @param array<string, mixed> $parameters Should be an empty array by default
203
     * @param array<string, mixed> $typoScript The TypoScript configuration
204
     */
205
    protected function parseAdditionalGetParameters(
206
        array &$parameters,
207
        array $typoScript
208
    ): void {
NEW
209
        foreach ($typoScript as $key => $value) {
×
NEW
210
            if (is_array($value)) {
×
NEW
211
                $key = rtrim($key, '.');
×
NEW
212
                $parameters[$key] = [];
×
NEW
213
                $this->parseAdditionalGetParameters($parameters[$key], $value);
×
214
            } else {
NEW
215
                $parameters[$key] = $value;
×
216
            }
217
        }
218
    }
219
}
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