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

CPS-IT / handlebars / 18679356355

21 Oct 2025 09:28AM UTC coverage: 85.455% (-5.4%) from 90.862%
18679356355

Pull #481

github

web-flow
Merge eeebdd715 into 1da7deba8
Pull Request #481: [FEATURE] Introduce `process-variables` data processor

5 of 64 new or added lines in 4 files covered. (7.81%)

846 of 990 relevant lines covered (85.45%)

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

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

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

125
        // Process variables with temporary cObj
NEW
126
        $processor = Renderer\Variables\VariableProcessor::for($cObj);
×
NEW
127
        $processedVariables = $processor->process($variables);
×
128

129
        // Apply processed variables, either override processed data (if no target variable name is given)
130
        // or merge with processed data using given target variable name ("as")
NEW
131
        if ($as === null) {
×
NEW
132
            $processedData = $processedVariables;
×
133
        } else {
NEW
134
            $processedData[$as] = $processedVariables;
×
135
        }
136

NEW
137
        return $processedData;
×
138
    }
139
}
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