• 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/Service/UrlService.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace YoastSeoForTypo3\YoastSeo\Service;
6

7
use Psr\EventDispatcher\EventDispatcherInterface;
8
use Psr\Http\Message\UriInterface;
9
use TYPO3\CMS\Backend\Routing\UriBuilder;
10
use TYPO3\CMS\Backend\Utility\BackendUtility;
11
use TYPO3\CMS\Core\Domain\Repository\PageRepository;
12
use TYPO3\CMS\Core\Exception\SiteNotFoundException;
13
use TYPO3\CMS\Core\Routing\RouteNotFoundException;
14
use TYPO3\CMS\Core\SingletonInterface;
15
use TYPO3\CMS\Core\Site\Entity\Site;
16
use TYPO3\CMS\Core\Site\SiteFinder;
17
use YoastSeoForTypo3\YoastSeo\Event\ModifyPreviewUrlEvent;
18
use YoastSeoForTypo3\YoastSeo\Utility\YoastUtility;
19

20
class UrlService implements SingletonInterface
21
{
22
    public function __construct(
23
        protected UriBuilder $uriBuilder,
24
        protected SiteFinder $siteFinder,
25
        protected PageRepository $pageRepository,
26
        protected EventDispatcherInterface $eventDispatcher,
NEW
27
    ) {}
×
28

29
    public function getPreviewUrl(
30
        int $pageId,
31
        int $languageId,
32
        string $additionalGetVars = ''
33
    ): string {
34
        return (string)$this->uriBuilder->buildUriFromRoute('ajax_yoast_preview', [
×
35
            'pageId' => $pageId,
×
36
            'languageId' => $languageId,
×
NEW
37
            'additionalGetVars' => urlencode($additionalGetVars),
×
38
        ]);
×
39
    }
40

41
    public function getUriToCheck(int $pageId, int $languageId, string $additionalGetVars): string
42
    {
43
        $this->checkMountpoint($pageId, $additionalGetVars);
×
44
        $rootLine = $this->getRootLine($pageId);
×
45
        $site = $this->getSite($pageId, $rootLine);
×
46

NEW
47
        if ($site === null) {
×
NEW
48
            return '';
×
49
        }
50

NEW
51
        $uriToCheck = YoastUtility::fixAbsoluteUrl(
×
NEW
52
            (string)$this->generateUri($site, $pageId, $languageId, $additionalGetVars)
×
NEW
53
        );
×
54

55
        /** @var ModifyPreviewUrlEvent $event */
NEW
56
        $event = $this->eventDispatcher->dispatch(
×
NEW
57
            new ModifyPreviewUrlEvent(
×
NEW
58
                $uriToCheck,
×
NEW
59
                $site,
×
NEW
60
                $pageId,
×
NEW
61
                $languageId
×
NEW
62
            )
×
NEW
63
        );
×
NEW
64
        return $event->getUrl();
×
65
    }
66

67
    public function checkMountPoint(int &$pageId, string &$additionalGetVars): void
68
    {
NEW
69
        $mountPointInformation = $this->pageRepository->getMountPointInfo($pageId);
×
70
        if ($mountPointInformation && $mountPointInformation['overlay']) {
×
71
            // New page id
72
            $pageId = $mountPointInformation['mount_pid'];
×
73
            $additionalGetVars .= '&MP=' . $mountPointInformation['MPvar'];
×
74
        }
75
    }
76

77
    /**
78
     * @return array<string, mixed>
79
     */
80
    public function getRootLine(int $pageId): array
81
    {
82
        return BackendUtility::BEgetRootLine($pageId);
×
83
    }
84

85
    /**
86
     * @param array<string, mixed> $rootLine
87
     */
88
    public function getSite(int $pageId, array $rootLine): ?Site
89
    {
90
        try {
NEW
91
            return $this->siteFinder->getSiteByPageId($pageId, $rootLine);
×
NEW
92
        } catch (SiteNotFoundException) {
×
93
            return null;
×
94
        }
95
    }
96

97
    public function generateUri(Site $site, int $pageId, int $languageId, string $additionalGetVars = ''): UriInterface
98
    {
99
        $additionalQueryParams = [];
×
100
        $additionalGetVars = rawurldecode($additionalGetVars);
×
101
        parse_str($additionalGetVars, $additionalQueryParams);
×
102
        $additionalQueryParams['_language'] = $site->getLanguageById($languageId);
×
103
        return $site->getRouter()->generateUri($pageId, $additionalQueryParams);
×
104
    }
105

106
    public function getSaveScoresUrl(): string
107
    {
108
        try {
109
            return (string)$this->uriBuilder->buildUriFromRoute('ajax_yoast_save_scores');
×
110
        } catch (RouteNotFoundException) {
×
111
            return '';
×
112
        }
113
    }
114

115
    public function getProminentWordsUrl(): string
116
    {
117
        try {
118
            return (string)$this->uriBuilder->buildUriFromRoute('ajax_yoast_prominent_words');
×
119
        } catch (RouteNotFoundException) {
×
120
            return '';
×
121
        }
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