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

FluidTYPO3 / vhs / 14862018726

06 May 2025 02:17PM UTC coverage: 72.09% (-0.02%) from 72.109%
14862018726

push

github

NamelessCoder
[BUGFIX] Read tag attributes with fallback to arguments

0 of 10 new or added lines in 2 files covered. (0.0%)

5649 of 7836 relevant lines covered (72.09%)

20.0 hits per line

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

25.0
/Classes/ViewHelpers/Page/Header/MetaViewHelper.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\Traits\TagViewHelperTrait;
13
use FluidTYPO3\Vhs\Utility\ContextUtility;
14
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractTagBasedViewHelper;
15

16
/**
17
 * ViewHelper used to render a meta tag
18
 *
19
 * If you use the ViewHelper in a plugin it has to be USER
20
 * not USER_INT, what means it has to be cached!
21
 */
22
class MetaViewHelper extends AbstractTagBasedViewHelper
23
{
24
    use TagViewHelperTrait;
25
    use PageRendererTrait;
26

27
    /**
28
     * @var string
29
     */
30
    protected $tagName = 'meta';
31

32
    public function initializeArguments(): void
33
    {
34
        parent::initializeArguments();
7✔
35
        $this->registerTagAttribute('name', 'string', 'Name property of meta tag');
7✔
36
        $this->registerTagAttribute('http-equiv', 'string', 'Property: http-equiv');
7✔
37
        $this->registerTagAttribute('property', 'string', 'Property of meta tag');
7✔
38
        $this->registerTagAttribute('content', 'string', 'Content of meta tag');
7✔
39
        $this->registerTagAttribute('scheme', 'string', 'Property: scheme');
7✔
40
        $this->registerTagAttribute('lang', 'string', 'Property: lang');
7✔
41
        $this->registerTagAttribute('dir', 'string', 'Property: dir');
7✔
42
    }
43

44
    /**
45
     * Render method
46
     *
47
     * @return string
48
     */
49
    public function render()
50
    {
51
        if (ContextUtility::isBackend()) {
×
52
            return '';
×
53
        }
54
        /** @var string|null $content */
55
        $content = $this->arguments['content'];
×
56
        if (!empty($content)) {
×
57
            $pageRenderer = static::getPageRenderer();
×
58
            if (method_exists($pageRenderer, 'addMetaTag')) {
×
59
                $pageRenderer->addMetaTag($this->renderTag($this->tagName, null, ['content' => $content]));
×
60
            } elseif (method_exists($pageRenderer, 'setMetaTag')) {
×
61
                $properties = [];
×
62
                $type = 'name';
×
63
                /** @var string $name */
NEW
64
                $name = $this->tag->getAttribute('name') ?? $this->arguments['name'];
×
NEW
65
                if (!empty($this->tag->getAttribute('property') ?? $this->arguments['property'] ?? null)) {
×
66
                    $type = 'property';
×
67
                    /** @var string $name */
NEW
68
                    $name = $this->tag->getAttribute('property') ?? $this->arguments['property'];
×
NEW
69
                } elseif (!empty($this->tag->getAttribute('http-equiv') ?? $this->arguments['http-equiv'] ?? null)) {
×
70
                    $type = 'http-equiv';
×
71
                    /** @var string $name */
NEW
72
                    $name = $this->tag->getAttribute('http-equiv') ?? $this->arguments['http-equiv'];
×
73
                }
74
                foreach (['http-equiv', 'property', 'scheme', 'lang', 'dir'] as $propertyName) {
×
NEW
75
                    if (!empty($this->tag->getAttribute($propertyName) ?? $this->arguments[$propertyName] ?? null)) {
×
NEW
76
                        $properties[$propertyName] = $this->tag->getAttribute($propertyName)
×
NEW
77
                            ?? $this->arguments[$propertyName]
×
NEW
78
                            ?? null;
×
79
                    }
80
                }
81
                $pageRenderer->setMetaTag($type, $name, $content, $properties);
×
82
            }
83
        }
84
        return '';
×
85
    }
86
}
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