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

CPS-IT / handlebars / 18835977706

27 Oct 2025 09:22AM UTC coverage: 85.282% (-5.6%) from 90.862%
18835977706

Pull #481

github

web-flow
Merge 7fc2b19ce into 3722fc2ac
Pull Request #481: [FEATURE] Introduce `process-variables` data processor

5 of 66 new or added lines in 4 files covered. (7.58%)

846 of 992 relevant lines covered (85.28%)

5.35 hits per line

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

0.0
/Classes/DataProcessing/ProcessVariablesProcessor.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\DataProcessing;
19

20
use CPSIT\Typo3Handlebars\Exception;
21
use CPSIT\Typo3Handlebars\Renderer;
22
use Symfony\Component\DependencyInjection;
23
use TYPO3\CMS\Frontend;
24

25
/**
26
 * Data processor to process given variables, especially useful in combination with other data processors.
27
 *
28
 * Example (standalone):
29
 * =====================
30
 *
31
 * hero = HANDLEBARSTEMPLATE
32
 * hero {
33
 *   templateName = @hero
34
 *
35
 *   # ...
36
 *
37
 *   dataProcessing {
38
 *     10 = process-variables
39
 *     10 {
40
 *       if.isTrue.field = title
41
 *
42
 *       variables {
43
 *         header = TEXT
44
 *         header.field = title
45
 *
46
 *         teaser = TEXT
47
 *         teaser.field = teaser
48
 *         teaser.parseFunc < lib.parseFunc_RTE
49
 *
50
 *         # ...
51
 *       }
52
 *     }
53
 *   }
54
 * }
55
 *
56
 * Example (with other data processor):
57
 * ====================================
58
 *
59
 * accordion = HANDLEBARSTEMPLATE
60
 * accordion {
61
 *   templateName = @accordion
62
 *
63
 *   # ...
64
 *
65
 *   dataProcessing {
66
 *     10 = database-query
67
 *     10 {
68
 *       # ...
69
 *
70
 *       dataProcessing {
71
 *         10 = process-variables
72
 *         10 {
73
 *           tableName = tx_mysitepackage_domain_model_accordion_element
74
 *           as = accordionItem
75
 *           variables {
76
 *             template = @accordion-item
77
 *
78
 *             header = TEXT
79
 *             header.field = title
80
 *
81
 *             bodytext = TEXT
82
 *             bodytext.field = bodytext
83
 *             bodytext.parseFunc < lib.parseFunc_RTE
84
 *
85
 *             # ...
86
 *           }
87
 *         }
88
 *       }
89
 *     }
90
 *   }
91
 * }
92
 *
93
 * @author Elias Häußler <e.haeussler@familie-redlich.de>
94
 * @license GPL-2.0-or-later
95
 */
96
#[DependencyInjection\Attribute\AutoconfigureTag('data.processor', ['identifier' => 'process-variables'])]
97
final readonly class ProcessVariablesProcessor implements Frontend\ContentObject\DataProcessorInterface
98
{
99
    /**
100
     * @param array<string, mixed> $contentObjectConfiguration
101
     * @param array<string, mixed> $processorConfiguration
102
     * @param array<string|int, mixed> $processedData
103
     * @return array<string|int, mixed>
104
     * @throws Frontend\ContentObject\Exception\ContentRenderingException
105
     * @throws Exception\ReservedVariableCannotBeUsed
106
     */
NEW
107
    public function process(
×
108
        Frontend\ContentObject\ContentObjectRenderer $cObj,
109
        array $contentObjectConfiguration,
110
        array $processorConfiguration,
111
        array $processedData,
112
    ): array {
NEW
113
        $data = $processorConfiguration['data'] ?? $processedData['data'] ?? $cObj->data;
×
NEW
114
        $table = $processorConfiguration['table'] ?? $processedData['table'] ?? $cObj->getCurrentTable();
×
NEW
115
        $variables = $processorConfiguration['variables'] ?? null;
×
NEW
116
        $as = $processorConfiguration['as'] ?? null;
×
117

118
        // Early return if no variables to process are configured
NEW
119
        if (!\is_array($variables)) {
×
NEW
120
            return $processedData;
×
121
        }
122

123
        // Use temporary cObj for processing
NEW
124
        $cObj = clone $cObj;
×
NEW
125
        $cObj->start($data, $table);
×
126

127
        // Early return if processing should be skipped according to a configured condition
NEW
128
        if (\is_array($processorConfiguration['if.'] ?? null) && !$cObj->checkIf($processorConfiguration['if.'])) {
×
NEW
129
            return $processedData;
×
130
        }
131

132
        // Process variables with temporary cObj
NEW
133
        $processor = Renderer\Variables\VariableProcessor::for($cObj);
×
NEW
134
        $processedVariables = $processor->process($variables);
×
135

136
        // Apply processed variables, either override processed data (if no target variable name is given)
137
        // or merge with processed data using given target variable name ("as")
NEW
138
        if ($as === null) {
×
NEW
139
            $processedData = $processedVariables;
×
140
        } else {
NEW
141
            $processedData[$as] = $processedVariables;
×
142
        }
143

NEW
144
        return $processedData;
×
145
    }
146
}
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