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

CPS-IT / handlebars / 34328655002

09 Sep 2026 08:21AM UTC coverage: 87.932% (-2.6%) from 90.565%
34328655002

push

github

web-flow
Merge pull request #636 from CPS-IT/feature/media-processor

[FEATURE] Introduce `media` processor

0 of 53 new or added lines in 2 files covered. (0.0%)

1603 of 1823 relevant lines covered (87.93%)

7.11 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 = image
47
 *
48
 *       config {
49
 *         image {
50
 *           sourceSets {
51
 *             default {
52
 *               maxW = 600c
53
 *             }
54
 *           }
55
 *         }
56
 *       }
57
 *     }
58
 *   }
59
 * }
60
 *
61
 * @author Elias Häußler <e.haeussler@familie-redlich.de>
62
 * @license GPL-2.0-or-later
63
 */
64
#[DependencyInjection\Attribute\AutoconfigureTag('data.processor', ['identifier' => 'media'])]
65
final readonly class MediaProcessor implements Frontend\ContentObject\DataProcessorInterface
66
{
67
    use DataSource\SupportsDataSource;
68
    use DataSource\SupportsDataSourceAwareProcessing;
69

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

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

NEW
100
        $file = $this->provideData($cObj, $collection, 'file');
×
101

102
        // Early return if file cannot be resolved
NEW
103
        if ($file === null) {
×
NEW
104
            return $processedData;
×
105
        }
106

107
        /** @var string $as */
NEW
108
        $as = $collection->resolve('as', DataSource\DataSource::ProcessorConfiguration, 'result');
×
NEW
109
        $fileConfig = $collection->resolve('config.', DataSource\DataSource::ProcessorConfiguration, []);
×
110

111
        // Convert file config
NEW
112
        if (is_array($fileConfig) && $fileConfig !== []) {
×
NEW
113
            $fileConfig = $this->typoScriptService->convertTypoScriptArrayToPlainArray($fileConfig);
×
114
        } else {
NEW
115
            $fileConfig = [];
×
116
        }
117

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

NEW
128
                return $processedData;
×
129
            }
130
        }
131

NEW
132
        $this->logger->warning(
×
NEW
133
            'No suitable media processor found while processing {table}:{uid}.',
×
NEW
134
            [
×
NEW
135
                'table' => $cObj->getCurrentTable(),
×
NEW
136
                'uid' => $collection->resolveCurrentUid(),
×
NEW
137
            ],
×
NEW
138
        );
×
139

NEW
140
        return $processedData;
×
141
    }
142
}
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