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

fnagel / t3extblog / 23823603081

31 Mar 2026 11:05PM UTC coverage: 37.437% (-12.6%) from 50.045%
23823603081

push

github

fnagel
[FEATURE] Add YAML lint to composer scripts and CI

Using the new TYPO3 14.2 built in YAML linter.

https://docs.typo3.org/c/typo3/cms-core/main/en-us/Changelog/13.3/Feature-104973-ActivateLintYamlExecutableForTYPO3.html

1256 of 3355 relevant lines covered (37.44%)

3.11 hits per line

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

0.0
/Classes/ViewHelpers/Frontend/Uri/ActionViewHelper.php
1
<?php
2

3
namespace FelixNagel\T3extblog\ViewHelpers\Frontend\Uri;
4

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

12
use FelixNagel\T3extblog\Exception\Exception;
13
use FelixNagel\T3extblog\Exception\InvalidArgumentException;
14
use Psr\Http\Message\ServerRequestInterface;
15
use TYPO3\CMS\Core\Utility\ArrayUtility;
16
use TYPO3\CMS\Core\Utility\GeneralUtility;
17
use TYPO3\CMS\Extbase\Mvc\RequestInterface;
18
use TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder;
19
use TYPO3\CMS\Extbase\Service\ExtensionService;
20
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
21
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
22

23
/**
24
 * A view helper for creating URIs to extbase actions.
25
 *
26
 * This a modified version of the default Extbase class forcing FE links within BE context.
27
 */
28
class ActionViewHelper extends AbstractViewHelper
29
{
30
    public function initializeArguments(): void
×
31
    {
32
        $this->registerArgument('action', 'string', 'Target action');
×
33
        $this->registerArgument('arguments', 'array', 'Arguments', false, []);
×
34
        $this->registerArgument('controller', 'string', 'Target controller. If NULL current controllerName is used');
×
35
        $this->registerArgument('extensionName', 'string', 'Target Extension Name (without `tx_` prefix and no underscores). If NULL the current extension name is used');
×
36
        $this->registerArgument('pluginName', 'string', 'Target plugin. If empty, the current plugin name is used');
×
37
        $this->registerArgument('pageUid', 'int', 'Target page. See TypoLink destination');
×
38
        $this->registerArgument('pageType', 'int', 'Type of the target page. See typolink.parameter', false, 0);
×
39
        $this->registerArgument('noCache', 'bool', 'Set this to disable caching for the target page. You should not need this.', false);
×
40
        $this->registerArgument('section', 'string', 'The anchor to be added to the URI', false, '');
×
41
        $this->registerArgument('format', 'string', 'The requested format, e.g. ".html', false, '');
×
42
        $this->registerArgument('linkAccessRestrictedPages', 'bool', 'If set, links pointing to access restricted pages will still link to the page even though the page cannot be accessed.', false, false);
×
43
        $this->registerArgument('additionalParams', 'array', 'additional query parameters that won\'t be prefixed like $arguments (overrule $arguments)', false, []);
×
44
        $this->registerArgument('absolute', 'bool', 'If set, an absolute URI is rendered', false, false);
×
45
        $this->registerArgument('addQueryString', 'string', 'If set, the current query parameters will be kept in the URL. If set to "untrusted", then ALL query parameters will be added. Be aware, that this might lead to problems when the generated link is cached.', false, false);
×
46
        $this->registerArgument('argumentsToBeExcludedFromQueryString', 'array', 'arguments to be removed from the URI. Only active if $addQueryString = TRUE', false, []);
×
47
    }
48

49
    public function render(): string
×
50
    {
51
        $request = null;
×
52
        if ($this->renderingContext->hasAttribute(ServerRequestInterface::class)) {
×
53
            $request = $this->renderingContext->getAttribute(ServerRequestInterface::class);
×
54
        }
55

56
        if (!$request instanceof RequestInterface) {
×
57
            throw new Exception(
×
58
                'ViewHelper t3b:uri.action can be used only in extbase context and needs a request implementing extbase RequestInterface.',
×
59
                1639819692
×
60
            );
×
61
        }
62

63
        return self::renderFrontend($this->arguments, $this->renderingContext);
×
64
    }
65

66
    /**
67
     * Always renders a FE link but with limited functionality.
68
     *
69
     * Some more arguments are required due to routing limitations.
70
     *
71
     * @SuppressWarnings("PHPMD.CyclomaticComplexity")
72
     * @SuppressWarnings("PHPMD.NPathComplexity")
73
     * @SuppressWarnings(PHPMD.UnusedFormalParameter)
74
     *
75
     * @see \TYPO3\CMS\Fluid\ViewHelpers\Uri\ActionViewHelper::render
76
     * @return string
77
     */
78
    protected static function renderFrontend(array $arguments, RenderingContextInterface $renderingContext)
×
79
    {
80
        /** @var RequestInterface $request */
81
        $request = $renderingContext->getAttribute(ServerRequestInterface::class);
×
82

83
        if ($arguments['pageUid'] === null || !(int) $arguments['pageUid']) {
×
84
            throw new InvalidArgumentException('Missing pageUid argument for extbase link generation from BE context. Check your template!');
×
85
        }
86

87
        if ($arguments['controller'] === null || $arguments['extensionName'] === null || $arguments['pluginName'] === null) {
×
88
            throw new InvalidArgumentException('Missing arguments for extbase link generation from BE context. Check your template!');
×
89
        }
90

91
        /** @var int $pageUid */
92
        $pageUid = $arguments['pageUid'] ?? 0;
×
93
        /** @var int $pageType */
94
        $pageType = $arguments['pageType'] ?? 0;
×
95
        /** @var bool $noCache */
96
        $noCache = $arguments['noCache'] ?? false;
×
97
        /** @var string|null $section */
98
        $section = $arguments['section'] ?? null;
×
99
        /** @var string|null $format */
100
        $format = $arguments['format'] ?? null;
×
101
        /** @var bool $linkAccessRestrictedPages */
102
        $linkAccessRestrictedPages = $arguments['linkAccessRestrictedPages'] ?? false;
×
103
        /** @var array|null $additionalParams */
104
        $additionalParams = $arguments['additionalParams'] ?? null;
×
105
        /** @var bool $absolute */
106
        $absolute = $arguments['absolute'] ?? false;
×
107
        /** @var bool|string $addQueryString */
108
        $addQueryString = $arguments['addQueryString'] ?? false;
×
109
        /** @var array|null $argumentsToBeExcludedFromQueryString */
110
        $argumentsToBeExcludedFromQueryString = $arguments['argumentsToBeExcludedFromQueryString'] ?? null;
×
111
        /** @var string|null $action */
112
        $action = $arguments['action'] ?? null;
×
113
        /** @var string|null $controller */
114
        $controller = $arguments['controller'] ?? null;
×
115
        /** @var string|null $extensionName */
116
        $extensionName = $arguments['extensionName'] ?? null;
×
117
        /** @var string|null $pluginName */
118
        $pluginName = $arguments['pluginName'] ?? null;
×
119
        /** @var array|null $arguments */
120
        $arguments = self::uriFor($action, $arguments['arguments'], $controller, $extensionName, $pluginName);
×
121

122
        /** @var UriBuilder $uriBuilder */
123
        $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
×
124
        $uriBuilder->reset()->setRequest($request);
×
125

126
        if ($pageUid > 0) {
×
127
            $uriBuilder->setTargetPageUid($pageUid);
×
128
        }
129

130
        if ($pageType > 0) {
×
131
            $uriBuilder->setTargetPageType($pageType);
×
132
        }
133

134
        if ($noCache) {
×
135
            $uriBuilder->setNoCache($noCache);
×
136
        }
137

138
        if (is_string($section)) {
×
139
            $uriBuilder->setSection($section);
×
140
        }
141

142
        if (is_string($format)) {
×
143
            $uriBuilder->setFormat($format);
×
144
        }
145

146
        if (is_array($additionalParams)) {
×
147
            ArrayUtility::mergeRecursiveWithOverrule($arguments, $additionalParams);
×
148
        }
149

150
        if ($absolute) {
×
151
            $uriBuilder->setCreateAbsoluteUri($absolute);
×
152
        }
153

154
        if ($addQueryString && $addQueryString !== 'false') {
×
155
            $uriBuilder->setAddQueryString($addQueryString);
×
156
        }
157

158
        if (is_array($argumentsToBeExcludedFromQueryString)) {
×
159
            $uriBuilder->setArgumentsToBeExcludedFromQueryString($argumentsToBeExcludedFromQueryString);
×
160
        }
161

162
        if ($linkAccessRestrictedPages) {
×
163
            $uriBuilder->setLinkAccessRestrictedPages($linkAccessRestrictedPages);
×
164
        }
165

166
        $uriBuilder->setArguments($arguments);
×
167

168
        return $uriBuilder->buildFrontendUri();
×
169
    }
170

171
    /** Simplified version of UriBuilder::uriFor
172
     *
173
     * @see \TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder::uriFor
174
     */
175
    protected static function uriFor(
×
176
        ?string $actionName = null,
177
        ?array $controllerArguments = null,
178
        ?string $controllerName = null,
179
        ?string $extensionName = null,
180
        ?string $pluginName = null
181
    ): array {
182
        /* @var $extensionService ExtensionService */
183
        $extensionService = GeneralUtility::makeInstance(ExtensionService::class);
×
184

185
        $controllerArguments ??= [];
×
186

187
        if ($actionName !== null) {
×
188
            $controllerArguments['action'] = $actionName;
×
189
        }
190

191
        if ($controllerName !== null) {
×
192
            $controllerArguments['controller'] = $controllerName;
×
193
        }
194

195
        if ($pluginName === null) {
×
196
            $pluginName = $extensionService->getPluginNameByAction(
×
197
                $extensionName,
×
198
                $controllerArguments['controller'],
×
199
                $controllerArguments['action'] ?? null
×
200
            );
×
201
        }
202

203
        $pluginNamespace = $extensionService->getPluginNamespace($extensionName, $pluginName);
×
204

205
        return [$pluginNamespace => $controllerArguments];
×
206
    }
207
}
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