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

FluidTYPO3 / vhs / 13566190336

27 Feb 2025 12:18PM UTC coverage: 72.127% (-0.6%) from 72.746%
13566190336

push

github

NamelessCoder
[TER] 7.1.0

5649 of 7832 relevant lines covered (72.13%)

20.01 hits per line

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

61.54
/Classes/ViewHelpers/Content/Random/RenderViewHelper.php
1
<?php
2
namespace FluidTYPO3\Vhs\ViewHelpers\Content\Random;
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\ArgumentOverride;
12
use FluidTYPO3\Vhs\Utility\ContextUtility;
13
use FluidTYPO3\Vhs\ViewHelpers\Content\AbstractContentViewHelper;
14

15
/**
16
 * ViewHelper for rendering a random content element in Fluid page templates.
17
 */
18
class RenderViewHelper extends AbstractContentViewHelper
19
{
20
    use ArgumentOverride;
21

22
    public function initializeArguments(): void
23
    {
24
        parent::initializeArguments();
14✔
25
        $this->overrideArgument('limit', 'integer', 'Optional limit number of content elements to render', false, 1);
14✔
26
    }
27

28
    /**
29
     * Render method
30
     *
31
     * @return string|array
32
     */
33
    public function render()
34
    {
35
        if (ContextUtility::isBackend()) {
14✔
36
            return '';
×
37
        }
38
        // Remove limit for getContentRecords()
39
        /** @var int $limit */
40
        $limit = $this->arguments['limit'];
14✔
41
        $this->arguments['limit'] = null;
14✔
42
        // Just using getContentRecords with a limit of 1 would not support
43
        // using slideCollect as collecting would stop as soon as one record
44
        // was found. As a potential optimization, $render could be overrided
45
        // so all the content records that end up unused do not get rendered.
46
        $contentRecords = $this->getContentRecords();
14✔
47
        if (!empty($contentRecords)) {
14✔
48
            shuffle($contentRecords);
×
49
            $contentRecords = array_slice($contentRecords, 0, $limit);
×
50
            if ($this->arguments['render']) {
×
51
                $contentRecords = implode(LF, $contentRecords);
×
52
            }
53
        }
54
        return $contentRecords;
14✔
55
    }
56
}
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