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

CPS-IT / handlebars-forms / 23533356140

25 Mar 2026 09:11AM UTC coverage: 0.758% (-0.02%) from 0.778%
23533356140

push

github

eliashaeussler
[FEATURE] Pass `<option>` child nodes as children to `<select>` ViewModel

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

24 existing lines in 1 file now uncovered.

7 of 923 relevant lines covered (0.76%)

0.03 hits per line

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

0.0
/Classes/Fluid/ViewHelperInvocationResult.php
1
<?php
2

3
declare(strict_types=1);
4

5
/*
6
 * This file is part of the TYPO3 CMS extension "handlebars_forms".
7
 *
8
 * It is free software; you can redistribute it and/or modify it under
9
 * the terms of the GNU General Public License, either version 2
10
 * of the License, or any later version.
11
 *
12
 * For the full copyright and license information, please read the
13
 * LICENSE.txt file that was distributed with this source code.
14
 *
15
 * The TYPO3 project - inspiring people to share!
16
 */
17

18
namespace CPSIT\Typo3HandlebarsForms\Fluid;
19

20
use CPSIT\Typo3HandlebarsForms\Domain;
21
use TYPO3\CMS\Fluid;
22
use TYPO3Fluid\Fluid as FluidStandalone;
23

24
/**
25
 * ViewHelperInvocationResult
26
 *
27
 * @author Elias Häußler <e.haeussler@familie-redlich.de>
28
 * @license GPL-2.0-or-later
29
 */
30
final readonly class ViewHelperInvocationResult
31
{
UNCOV
32
    public function __construct(
×
33
        public FluidStandalone\Core\ViewHelper\ViewHelperInterface $viewHelper,
34
        public Fluid\Core\Rendering\RenderingContext $renderingContext,
35
        public mixed $content,
36
        public FluidStandalone\Core\ViewHelper\TagBuilder $tag = new FluidStandalone\Core\ViewHelper\TagBuilder(),
UNCOV
37
    ) {}
×
38

39
    /**
40
     * @param non-empty-string $tagName
41
     * @return list<Domain\Renderable\ViewModel\ViewModel>
42
     */
UNCOV
43
    public function extractChildNodes(string $tagName): array
×
44
    {
UNCOV
45
        $content = $this->tag->getContent();
×
UNCOV
46
        $children = [];
×
47

48
        // Early return if no content is provided
UNCOV
49
        if ($content === null) {
×
UNCOV
50
            return [];
×
51
        }
52

53
        // Enforce UTF-8 on the rendered tag content
UNCOV
54
        $useInternalErrors = libxml_use_internal_errors(true);
×
UNCOV
55
        $html = '<?xml encoding="UTF-8">' . $content;
×
56

57
        // Load tag content as DOMDocument
58
        try {
UNCOV
59
            $dom = new \DOMDocument();
×
UNCOV
60
            $dom->loadHTML($html, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
×
61
        } finally {
UNCOV
62
            libxml_use_internal_errors($useInternalErrors);
×
63
        }
64

65
        // Parse nodes
UNCOV
66
        $xpath = new \DOMXPath($dom);
×
UNCOV
67
        $nodes = $xpath->query('//' . $tagName);
×
68

69
        // Early return if queried nodes are invalid
UNCOV
70
        if (!($nodes instanceof \DOMNodeList)) {
×
UNCOV
71
            return [];
×
72
        }
73

74
        // Convert nodes to view models
UNCOV
75
        foreach ($nodes as $node) {
×
UNCOV
76
            if (!($node instanceof \DOMElement)) {
×
UNCOV
77
                continue;
×
78
            }
79

UNCOV
80
            $tag = new FluidStandalone\Core\ViewHelper\TagBuilder($tagName, trim($node->textContent));
×
81

82
            /** @var \DOMAttr $attribute */
UNCOV
83
            foreach ($node->attributes as $attribute) {
×
UNCOV
84
                $tag->addAttribute($attribute->name, $attribute->value);
×
85
            }
86

UNCOV
87
            $children[] = new Domain\Renderable\ViewModel\ViewModel($this->renderingContext, null, $tag);
×
88
        }
89

UNCOV
90
        return $children;
×
91
    }
92
}
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