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

CPS-IT / handlebars / 32947410426

26 Aug 2026 08:22AM UTC coverage: 89.828% (+0.2%) from 89.629%
32947410426

push

github

web-flow
[!!!][FEATURE] Support content objects and data processing in `plugin.tx_handlebars.variables` (#623)

26 of 27 new or added lines in 3 files covered. (96.3%)

1 existing line in 1 file now uncovered.

1563 of 1740 relevant lines covered (89.83%)

6.89 hits per line

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

94.87
/Classes/Renderer/Variables/TypoScriptVariableProvider.php
1
<?php
2

3
declare(strict_types=1);
4

5
/*
6
 * This file is part of the TYPO3 CMS extension "handlebars".
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\Typo3Handlebars\Renderer\Variables;
19

20
use CPSIT\Typo3Handlebars\Extension;
21
use Psr\Http\Message;
22
use TYPO3\CMS\Core;
23
use TYPO3\CMS\Extbase;
24
use TYPO3\CMS\Frontend;
25

26
/**
27
 * TypoScriptVariableProvider
28
 *
29
 * @author Elias Häußler <e.haeussler@familie-redlich.de>
30
 * @license GPL-2.0-or-later
31
 */
32
final class TypoScriptVariableProvider implements RequestAwareVariableProvider
33
{
34
    /**
35
     * @var array<string|int, mixed>|null
36
     */
37
    private ?array $variables = null;
38
    private ?Message\ServerRequestInterface $request = null;
39

40
    public function __construct(
8 ✔
41
        private readonly Extbase\Configuration\ConfigurationManagerInterface $configurationManager,
42
        private readonly Frontend\ContentObject\ContentDataProcessor $contentDataProcessor,
43
        private readonly Core\TypoScript\TypoScriptService $typoScriptService,
44
    ) {}
8 ✔
45

46
    public function get(): array
5 ✔
47
    {
48
        if ($this->variables === null) {
5 ✔
49
            $this->variables = $this->fetchVariables();
5 ✔
50
        }
51

52
        return $this->variables ?? [];
5 ✔
53
    }
54

55
    public function isCacheable(): bool
1 ✔
56
    {
57
        // Once we have a request attached, the resulting variables can be safely cached.
58
        // Otherwise, caching should be avoided until we can resolve and process all variables
59
        // in the context of the given request.
60
        return $this->request !== null;
1 ✔
61
    }
62

63
    public function offsetExists(mixed $offset): bool
1 ✔
64
    {
65
        return isset($this->get()[$offset]);
1 ✔
66
    }
67

68
    public function offsetGet(mixed $offset): mixed
1 ✔
69
    {
70
        return $this->get()[$offset] ?? null;
1 ✔
71
    }
72

73
    public function offsetSet(mixed $offset, mixed $value): never
1 ✔
74
    {
75
        throw new \LogicException('Variables cannot be modified.', 1736274326);
1 ✔
76
    }
77

78
    public function offsetUnset(mixed $offset): never
1 ✔
79
    {
80
        throw new \LogicException('Variables cannot be modified.', 1736274336);
1 ✔
81
    }
82

83
    public function setRequest(Message\ServerRequestInterface $request): void
5 ✔
84
    {
85
        $this->request = $request;
5 ✔
86
    }
87

UNCOV
88
    public static function getPriority(): int
×
89
    {
90
        return 50;
×
91
    }
92

93
    /**
94
     * @return array<string|int, mixed>|null
95
     */
96
    private function fetchVariables(): ?array
5 ✔
97
    {
98
        $cObj = $this->resolveContentObjectRenderer();
5 ✔
99

100
        // Early return if content object renderer is not (yet) available, but don't persist
101
        // anything to allow variable resolution at a later time, where cObj might be available.
102
        if ($cObj === null) {
5 ✔
103
            return null;
1 ✔
104
        }
105

106
        $typoScriptConfiguration = $this->typoScriptService->convertPlainArrayToTypoScriptArray(
4 ✔
107
            $this->configurationManager->getConfiguration(
4 ✔
108
                Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK,
4 ✔
109
                Extension::NAME,
4 ✔
110
            ),
4 ✔
111
        );
4 ✔
112

113
        // Early return if variables are invalid
114
        if (!is_array($variables = $typoScriptConfiguration['variables.'] ?? null)) {
4 ✔
115
            return [];
1 ✔
116
        }
117

118
        // Process content object variables and simple variables
119
        $variables = VariablesProcessor::for($cObj)->process($variables);
3 ✔
120

121
        // Process variables with configured data processors
122
        return $this->contentDataProcessor->process($cObj, $typoScriptConfiguration, $variables);
3 ✔
123
    }
124

125
    private function resolveContentObjectRenderer(): ?Frontend\ContentObject\ContentObjectRenderer
5 ✔
126
    {
127
        $contentObjectRenderer = $this->request?->getAttribute('currentContentObject');
5 ✔
128

129
        if (!($contentObjectRenderer instanceof Frontend\ContentObject\ContentObjectRenderer)) {
5 ✔
130
            return null;
1 ✔
131
        }
132

133
        return $contentObjectRenderer;
4 ✔
134
    }
135
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc