• 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/StructuredData/BreadcrumbStructuredDataProvider.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace YoastSeoForTypo3\YoastSeo\StructuredData;
6

7
use TYPO3\CMS\Core\Context\Context;
8
use TYPO3\CMS\Core\Exception\SiteNotFoundException;
9
use TYPO3\CMS\Core\Site\SiteFinder;
10
use TYPO3\CMS\Core\Utility\GeneralUtility;
11
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
12

13
class BreadcrumbStructuredDataProvider implements StructuredDataProviderInterface
14
{
15
    /** @var array<string, mixed> */
16
    protected array $configuration;
17

18
    public function __construct(
19
        protected SiteFinder $siteFinder,
20
        protected Context $context,
21
    ) {}
×
22

23
    /**
24
     * @return array<array<string, mixed>>
25
     */
26
    public function getData(): array
27
    {
28
        $breadcrumbs = [];
×
29
        $excludedDoktypes = $this->getExcludedDoktypes();
×
30
        $iterator = 1;
×
31
        $siteRootFound = false;
×
32
        foreach ($this->getRootLine() as $page) {
×
33
            if ($page['hidden'] === 1) {
×
34
                continue;
×
35
            }
36
            $siteRootFound = $siteRootFound || $page['is_siteroot'];
×
37
            if (!$siteRootFound || in_array((int)$page['doktype'], $excludedDoktypes, true)) {
×
38
                continue;
×
39
            }
40
            $url = $this->getUrlForPage($page['uid']);
×
41
            if (empty($url)) {
×
42
                continue;
×
43
            }
44
            $breadcrumbs[] = [
×
45
                '@type' => 'ListItem',
×
46
                'position' => $iterator,
×
47
                'item' => [
×
48
                    '@id' => $url,
×
49
                    'name' => $page['nav_title'] ?: $page['title'],
×
50
                ],
×
51
            ];
×
52
            $iterator++;
×
53
        }
54

55
        return $this->getBreadcrumbList($breadcrumbs);
×
56
    }
57

58
    /**
59
     * @param array<array<string, mixed>> $breadcrumbs
60
     * @return array<array<string, mixed>>
61
     */
62
    protected function getBreadcrumbList(array $breadcrumbs): array
63
    {
64
        if (empty($breadcrumbs)) {
×
65
            return [];
×
66
        }
67

68
        return [
×
69
            [
×
70
                '@context' => 'https://www.schema.org',
×
71
                '@type' => 'BreadcrumbList',
×
72
                'itemListElement' => $breadcrumbs,
×
73
            ],
×
74
        ];
×
75
    }
76

77
    /**
78
     * @return int[]
79
     */
80
    protected function getExcludedDoktypes(): array
81
    {
82
        if (!empty($this->configuration['excludedDoktypes'] ?? '')) {
×
83
            return GeneralUtility::intExplode(',', $this->configuration['excludedDoktypes']);
×
84
        }
85
        return [];
×
86
    }
87

88
    /**
89
     * @return array<array<string, mixed>>
90
     */
91
    protected function getRootLine(): array
92
    {
93
        $rootLine = $this->getTyposcriptFrontendController()->rootLine ?: [];
×
94
        ksort($rootLine);
×
95
        return $rootLine;
×
96
    }
97

98
    protected function getUrlForPage(int $pageId): string
99
    {
100
        try {
101
            $site = $this->siteFinder->getSiteByPageId($pageId);
×
102
            return (string)$site->getRouter()->generateUri(
×
NEW
103
                $pageId,
×
NEW
104
                ['_language' => (int)$this->context->getPropertyFromAspect('language', 'id')]
×
105
            );
×
106
        } catch (SiteNotFoundException|\InvalidArgumentException) {
×
107
            return '';
×
108
        }
109
    }
110

111
    protected function getTyposcriptFrontendController(): TypoScriptFrontendController
112
    {
113
        return $GLOBALS['TSFE'];
×
114
    }
115

116
    /**
117
     * @param array<string, mixed> $configuration
118
     */
119
    public function setConfiguration(array $configuration): void
120
    {
121
        $this->configuration = $configuration;
×
122
    }
123
}
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