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

Yoast / Yoast-SEO-for-TYPO3 / 13327579701

14 Feb 2025 10:43AM UTC coverage: 1.276%. First build
13327579701

push

github

web-flow
Merge pull request #597 from Yoast/feature/v11

[FEATURE] Release 11.0.0

21 of 894 new or added lines in 76 files covered. (2.35%)

35 of 2744 relevant lines covered (1.28%)

0.04 hits per line

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

0.0
/Classes/Frontend/AdditionalPreviewData.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace YoastSeoForTypo3\YoastSeo\Frontend;
6

7
use TYPO3\CMS\Core\SingletonInterface;
8
use TYPO3\CMS\Core\Site\Entity\Site;
9
use TYPO3\CMS\Core\Site\Entity\SiteLanguage;
10
use TYPO3\CMS\Core\Utility\GeneralUtility;
11
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
12
use YoastSeoForTypo3\YoastSeo\Service\YoastRequestService;
13

14
class AdditionalPreviewData implements SingletonInterface
15
{
16
    /** @var array<string, mixed> */
17
    protected array $config;
18

19
    public function __construct(
20
        protected YoastRequestService $yoastRequestService
21
    ) {
22
        $this->config = $GLOBALS['TSFE']->tmpl->setup['config.'] ?? [];
×
23
    }
24

25
    /**
26
     * @param array<string, mixed> $params
27
     */
28
    public function render(array &$params, object $pObj): void
29
    {
30
        $serverParams = $GLOBALS['TYPO3_REQUEST'] ? $GLOBALS['TYPO3_REQUEST']->getServerParams() : $_SERVER;
×
NEW
31
        if (!$this->yoastRequestService->isValidRequest($serverParams)) {
×
32
            return;
×
33
        }
34

35
        $config = $this->getPageTitlePrependAppend();
×
36
        setcookie('yoast-preview-tstamp', (string)time()); // To prevent caching in for example varnish
×
37
        $params['headerData']['YoastPreview'] = '<meta name="x-yoast-title-config" value="' . $config['prepend'] . '|||' . $config['append'] . '" />';
×
38
    }
39

40
    protected function getWebsiteTitle(): string
41
    {
42
        $request = $GLOBALS['TYPO3_REQUEST'];
×
43
        $language = $request->getAttribute('language');
×
44
        if ($language instanceof SiteLanguage && !empty($language->getWebsiteTitle())) {
×
45
            return trim($language->getWebsiteTitle());
×
46
        }
47
        $site = $request->getAttribute('site');
×
48
        if ($site instanceof Site && !empty($site->getConfiguration()['websiteTitle'] ?? '')) {
×
49
            return trim($site->getConfiguration()['websiteTitle']);
×
50
        }
51

52
        if (!empty($GLOBALS['TSFE']->tmpl->setup['sitetitle'] ?? '')) {
×
53
            return trim($GLOBALS['TSFE']->tmpl->setup['sitetitle']);
×
54
        }
55

56
        return '';
×
57
    }
58

59
    /**
60
     * @return string[]
61
     */
62
    protected function getPageTitlePrependAppend(): array
63
    {
64
        $prependAppend = ['prepend' => '', 'append' => ''];
×
65
        $siteTitle = $this->getWebsiteTitle();
×
66
        $pageTitleFirst = (bool)($this->config['pageTitleFirst'] ?? false);
×
67
        $pageTitleSeparator = $this->getPageTitleSeparator();
×
68
        // only show a separator if there are both site title and page title
69
        if (empty($siteTitle)) {
×
70
            $pageTitleSeparator = '';
×
71
        } elseif (empty($pageTitleSeparator)) {
×
72
            // use the default separator if non given
73
            $pageTitleSeparator = ': ';
×
74
        }
75

76
        if ($pageTitleFirst) {
×
77
            $prependAppend['append'] = $pageTitleSeparator . $siteTitle;
×
78
        } else {
79
            $prependAppend['prepend'] = $siteTitle . $pageTitleSeparator;
×
80
        }
81

82
        return $prependAppend;
×
83
    }
84

85
    protected function getPageTitleSeparator(): string
86
    {
87
        if (!isset($this->config['pageTitleSeparator']) || $this->config['pageTitleSeparator'] === '') {
×
88
            return '';
×
89
        }
90

91
        if (is_array($this->config['pageTitleSeparator.'] ?? null)) {
×
92
            return (string)GeneralUtility::makeInstance(ContentObjectRenderer::class)
×
93
                ->stdWrap($this->config['pageTitleSeparator'], $this->config['pageTitleSeparator.']);
×
94
        }
95

96
        return $this->config['pageTitleSeparator'] . ' ';
×
97
    }
98
}
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