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

FluidTYPO3 / flux / 12237686280

09 Dec 2024 02:27PM UTC coverage: 92.9% (-0.5%) from 93.421%
12237686280

push

github

NamelessCoder
[TER] 10.1.0

7013 of 7549 relevant lines covered (92.9%)

56.22 hits per line

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

95.24
/Classes/ViewHelpers/Form/OptionViewHelper.php
1
<?php
2
declare(strict_types=1);
3
namespace FluidTYPO3\Flux\ViewHelpers\Form;
4

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

12
use FluidTYPO3\Flux\Form\OptionCarryingInterface;
13
use FluidTYPO3\Flux\ViewHelpers\AbstractFormViewHelper;
14
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
15

16
/**
17
 * Form option ViewHelper
18
 */
19
class OptionViewHelper extends AbstractFormViewHelper
20
{
21
    public static string $option = '';
22

23
    public function initializeArguments(): void
24
    {
25
        $this->registerArgument('value', 'string', 'Option value');
6✔
26
        $this->registerArgument('name', 'string', 'Name of the option to be set', true);
6✔
27
    }
28

29
    public function render()
30
    {
31
        return self::renderStatic($this->arguments, $this->buildRenderChildrenClosure(), $this->renderingContext);
×
32
    }
33

34
    public static function renderStatic(
35
        array $arguments,
36
        \Closure $renderChildrenClosure,
37
        RenderingContextInterface $renderingContext
38
    ): string {
39
        /** @var string $option */
40
        $option = $arguments['name'] ?? static::$option;
42✔
41
        $container = static::getContainerFromRenderingContext($renderingContext);
42✔
42
        $value = $renderChildrenClosure();
42✔
43
        if ($container instanceof OptionCarryingInterface) {
42✔
44
            $container->setOption($option, $value);
36✔
45
            return '';
36✔
46
        }
47
        throw new \UnexpectedValueException(
6✔
48
            'flux:form.option cannot be used as child element of '
6✔
49
            . get_class($container)
6✔
50
            . ' (this class does not support options). '
6✔
51
            . 'Please correct this in your template file(s). The option had name="'
6✔
52
            . $option
6✔
53
            . '" and value="'
6✔
54
            . $value
6✔
55
            . '"',
6✔
56
            1602693000
6✔
57
        );
6✔
58
    }
59

60
    public function getContentArgumentName(): ?string
61
    {
62
        return 'value';
24✔
63
    }
64
}
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