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

FluidTYPO3 / vhs / 5534149808

pending completion
5534149808

push

github

NamelessCoder
[BUGFIX] Use unicode-safe whitespace eradication regexp

Close: #1630

0 of 1 new or added line in 1 file covered. (0.0%)

5484 of 7504 relevant lines covered (73.08%)

11.37 hits per line

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

47.37
/Classes/ViewHelpers/Page/Header/TitleViewHelper.php
1
<?php
2
namespace FluidTYPO3\Vhs\ViewHelpers\Page\Header;
3

4
/*
5
 * This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
6
 *
7
 * For the full copyright and license information, please read the
8
 * LICENSE.md file that was distributed with this source code.
9
 */
10

11
use FluidTYPO3\Vhs\Traits\PageRendererTrait;
12
use FluidTYPO3\Vhs\Utility\ContextUtility;
13
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
14
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
15
use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
16

17
/**
18
 * ### ViewHelper used to override page title
19
 *
20
 * This ViewHelper uses the TYPO3 PageRenderer to set the
21
 * page title - with everything this implies regarding
22
 * support for TypoScript settings.
23
 *
24
 * Specifically you should note the setting `config.noPageTitle`
25
 * which must be set to either 1 (one) in case no other source
26
 * defines the page title (it's likely that at least one does),
27
 * or 2 (two) to indicate that the TS-controlled page title
28
 * must be disabled. A value of 2 (two) ensures that the title
29
 * used in this ViewHelper will be used in the rendered page.
30
 *
31
 * If you use the ViewHelper in a plugin it has to be USER
32
 * not USER_INT, what means it has to be cached!
33
 *
34
 * #### Why can I not forcibly override the title?
35
 *
36
 * This has been opted out with full intention. The reasoning
37
 * behind not allowing a Fluid template to forcibly override the
38
 * page title that may be set through TypoScript is that many
39
 * other extensions (mainly SEO-focused ones) will be setting
40
 * and manipulating the page title - and if overridden in a
41
 * template file using a ViewHelper, it would be almost impossible
42
 * to detect unless you already know exactly where to look.
43
 * Enforcing use of the core behavior is the only way to ensure
44
 * that this ViewHelper can coexist with other extensions in
45
 * a fully controllable way.
46
 */
47
class TitleViewHelper extends AbstractViewHelper
48
{
49
    use CompileWithRenderStatic;
50
    use PageRendererTrait;
51

52
    public function initializeArguments(): void
53
    {
54
        $this->registerArgument('title', 'string', 'Title tag content');
5✔
55
        $this->registerArgument(
5✔
56
            'whitespaceString',
5✔
57
            'string',
5✔
58
            'String used to replace groups of white space characters, one replacement inserted per group',
5✔
59
            false,
5✔
60
            ' '
5✔
61
        );
5✔
62
        $this->registerArgument('setIndexedDocTitle', 'boolean', 'Set indexed doc title to title', false, false);
5✔
63
    }
64

65
    /**
66
     * @return mixed
67
     */
68
    public static function renderStatic(
69
        array $arguments,
70
        \Closure $renderChildrenClosure,
71
        RenderingContextInterface $renderingContext
72
    ) {
73
        if (ContextUtility::isBackend()) {
×
74
            return;
×
75
        }
76
        if (!empty($arguments['title'])) {
×
77
            /** @var string $title */
78
            $title = $arguments['title'];
×
79
        } else {
80
            /** @var string $title */
81
            $title = $renderChildrenClosure();
×
82
        }
83
        /** @var string $whitespace */
84
        $whitespace = $arguments['whitespaceString'];
×
NEW
85
        $title = trim((string) preg_replace('/\s+/u', $whitespace, $title), $whitespace);
×
86
        static::getPageRenderer()->setTitle($title);
×
87
        if ($arguments['setIndexedDocTitle']) {
×
88
            $GLOBALS['TSFE']->indexedDocTitle = $title;
×
89
        }
90
    }
91
}
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