Passed
Push — main ( 52a7ec...5410b3 )
by Torben
03:32
created

PageViewHelper::renderWithExtbaseContext()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 32
Code Lines 26

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 26
nc 2
nop 2
dl 0
loc 32
rs 9.504
c 1
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of the TYPO3 CMS project.
5
 *
6
 * It is free software; you can redistribute it and/or modify it under
7
 * the terms of the GNU General Public License, either version 2
8
 * of the License, or any later version.
9
 *
10
 * For the full copyright and license information, please read the
11
 * LICENSE.txt file that was distributed with this source code.
12
 *
13
 * The TYPO3 project - inspiring people to share!
14
 */
15
16
namespace DERHANSEN\SfEventMgt\ViewHelpers\Uri;
17
18
use TYPO3\CMS\Core\Site\SiteFinder;
19
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
20
21
/**
22
 * ViewHelper to render a link to a page using the current core routing interface. Should be used in emails
23
 * sent via the notification backend module in order to create frontend links in email content.
24
 */
25
final class PageViewHelper extends AbstractViewHelper
26
{
27
    public function __construct(protected readonly SiteFinder $siteFinder)
28
    {
29
    }
30
31
    public function initializeArguments(): void
32
    {
33
        $this->registerArgument('pageUid', 'int', 'Target PID');
34
        $this->registerArgument('additionalParams', 'array', 'Query parameters to be attached to the resulting URI', false, []);
35
    }
36
37
    public function render(): string
38
    {
39
        $pageUid = (int)$this->arguments['pageUid'];
40
        $additionalParams = $this->arguments['additionalParams'];
41
        $site = $this->siteFinder->getSiteByPageId($pageUid);
42
        return (string)($site->getRouter()->generateUri((string)$pageUid, $additionalParams));
43
    }
44
}
45