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

CPS-IT / handlebars / 36402418035

28 Sep 2026 09:16AM UTC coverage: 87.788% (-0.1%) from 87.932%
36402418035

Pull #646

github

web-flow
Merge ad6f00170 into 542b94e71
Pull Request #646: [TASK] Make target variable in `media` processor optional

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

2 existing lines in 1 file now uncovered.

1603 of 1826 relevant lines covered (87.79%)

7.1 hits per line

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

0.0
/Classes/DataProcessing/MediaProcessor.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 Psr\Log;
21
use Symfony\Component\DependencyInjection;
22
use TYPO3\CMS\Core;
23
use TYPO3\CMS\Frontend;
24

25
/**
26
 * Data processor to resolve a file resource and run it through a matching media processor.
27
 *
28
 * Example:
29
 * ========
30
 *
31
 * Given a "files" processor has resolved file references into "files", the first one
32
 * can be passed to the built-in "image" media processor to generate responsive source sets:
33
 *
34
 * tt_content.textpic = HANDLEBARSTEMPLATE
35
 * tt_content.textpic {
36
 *   dataProcessing {
37
 *     10 = files
38
 *     10 {
39
 *       references.fieldName = image
40
 *       as = files
41
 *     }
42
 *
43
 *     20 = media
44
 *     20 {
45
 *       file = processedData:files.0
46
 *       # "as" can also be omitted here. The media processor's result would then be
47
 *       # merged recursively into the processed data instead of being nested under a key.
48
 *       as = image
49
 *
50
 *       config {
51
 *         # Here you can provide individual config for each available media processor.
52
 *         # Key (here: image) equals processor identifier (see #[AsTaggedItem] attributes).
53
 *         image {
54
 *           sourceSets {
55
 *             default {
56
 *               maxW = 600c
57
 *             }
58
 *           }
59
 *         }
60
 *       }
61
 *     }
62
 *   }
63
 * }
64
 *
65
 * @author Elias Häußler <e.haeussler@familie-redlich.de>
66
 * @license GPL-2.0-or-later
67
 */
68
#[DependencyInjection\Attribute\AutoconfigureTag('data.processor', ['identifier' => 'media'])]
69
final readonly class MediaProcessor implements Frontend\ContentObject\DataProcessorInterface
70
{
71
    use DataSource\SupportsDataSource;
72
    use DataSource\SupportsDataSourceAwareProcessing;
73

74
    /**
75
     * @param iterable<string, Media\MediaProcessor> $mediaProcessors
76
     */
77
    public function __construct(
×
78
        private Log\LoggerInterface $logger,
79
        #[DependencyInjection\Attribute\AutowireIterator('handlebars.media_processor', 'key')]
80
        private iterable $mediaProcessors,
81
        private Core\TypoScript\TypoScriptService $typoScriptService,
82
        private DataSource\DataSourceProvider $dataSourceProvider,
83
    ) {}
×
84

85
    /**
86
     * @param array<string, mixed> $contentObjectConfiguration
87
     * @param array<string, mixed> $processorConfiguration
88
     * @param array<string, mixed> $processedData
89
     * @return array<string, mixed>
90
     */
91
    public function process(
×
92
        Frontend\ContentObject\ContentObjectRenderer $cObj,
93
        array $contentObjectConfiguration,
94
        array $processorConfiguration,
95
        array $processedData,
96
    ): array {
97
        $collection = DataSource\DataSourceCollection::for(
×
98
            $cObj,
×
99
            $contentObjectConfiguration,
×
100
            $processorConfiguration,
×
101
            $processedData,
×
102
        );
×
103

104
        $file = $this->provideData($cObj, $collection, 'file');
×
105

106
        // Early return if file cannot be resolved
107
        if ($file === null) {
×
108
            return $processedData;
×
109
        }
110

111
        /** @var string|null $as */
NEW
112
        $as = $collection->resolve('as', DataSource\DataSource::ProcessorConfiguration);
×
UNCOV
113
        $fileConfig = $collection->resolve('config.', DataSource\DataSource::ProcessorConfiguration, []);
×
114

115
        // Convert file config
116
        if (is_array($fileConfig) && $fileConfig !== []) {
×
117
            $fileConfig = $this->typoScriptService->convertTypoScriptArrayToPlainArray($fileConfig);
×
118
        } else {
119
            $fileConfig = [];
×
120
        }
121

122
        foreach ($this->mediaProcessors as $name => $mediaProcessor) {
×
123
            if ($mediaProcessor->supports($file)) {
×
124
                /** @var array<string, mixed>|null $mediaProcessorConfiguration */
125
                $mediaProcessorConfiguration = $fileConfig[$name] ?? null;
×
NEW
126
                $processedVariables = $mediaProcessor->process(
×
127
                    $cObj,
×
128
                    $file,
×
129
                    is_array($mediaProcessorConfiguration) ? $mediaProcessorConfiguration : [],
×
130
                );
×
131

NEW
132
                if ($as === null) {
×
NEW
133
                    Core\Utility\ArrayUtility::mergeRecursiveWithOverrule($processedData, $processedVariables);
×
134
                    /** @var array<string, mixed> $processedData */
135
                } else {
NEW
136
                    $processedData[$as] = $processedVariables;
×
137
                }
138

UNCOV
139
                return $processedData;
×
140
            }
141
        }
142

143
        $this->logger->warning(
×
144
            'No suitable media processor found while processing {table}:{uid}.',
×
145
            [
×
146
                'table' => $cObj->getCurrentTable(),
×
147
                'uid' => $collection->resolveCurrentUid(),
×
148
            ],
×
149
        );
×
150

151
        return $processedData;
×
152
    }
153
}
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