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

TYPO3-Headless / headless / 9887449051

11 Jul 2024 07:40AM UTC coverage: 65.718% (-0.1%) from 65.849%
9887449051

Pull #748

github

web-flow
Merge 8ca0df7df into 44ffec997
Pull Request #748: [FEATURE] Allow return only one element in CONTENT_JSON

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

993 of 1511 relevant lines covered (65.72%)

2.79 hits per line

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

0.0
/Classes/DataProcessing/ExtractPropertyProcessor.php
1
<?php
2

3
/*
4
 * This file is part of the "headless" Extension for TYPO3 CMS.
5
 *
6
 * For the full copyright and license information, please read the
7
 * LICENSE.md file that was distributed with this source code.
8
 */
9

10
declare(strict_types=1);
11

12
namespace FriendsOfTYPO3\Headless\DataProcessing;
13

14
use TYPO3\CMS\Core\Utility\GeneralUtility;
15
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
16
use TYPO3\CMS\Frontend\ContentObject\DataProcessorInterface;
17

18
/**
19
 * Extract a single (maybe nested) property from a given array
20
 *
21
 * Example:
22
 * lib.meta.fields.ogImage = TEXT
23
 * lib.meta.fields.ogImage {
24
 *     dataProcessing {
25
 *         10 = FriendsOfTYPO3\Headless\DataProcessing\FilesProcessor
26
 *         ...
27
 *
28
 *         20 = FriendsOfTYPO3\Headless\DataProcessing\ExtractPropertyProcessor
29
 *         20.key = media.publicUrl
30
 *         20.as = media
31
 *     }
32
 * }
33
 */
34
class ExtractPropertyProcessor implements DataProcessorInterface
35
{
36
    /**
37
     * Extract a single (maybe nested) property from a given array
38
     *
39
     * @param ContentObjectRenderer $cObj The content object renderer, which contains data of the content element
40
     * @param array $contentObjectConfiguration The configuration of Content Object
41
     * @param array $processorConfiguration The configuration of this processor
42
     * @param array $processedData Key/value store of processed data (e.g. to be passed to a Fluid View)
43
     * @return array the processed data as key/value store
44
     */
45
    public function process(
46
        ContentObjectRenderer $cObj,
47
        array $contentObjectConfiguration,
48
        array $processorConfiguration,
49
        array $processedData
50
    ) {
51
        if (empty($processorConfiguration['as'])) {
×
52
            throw new \Exception('Please specify property \'as\'');
×
53
        }
54

55
        if (empty($processorConfiguration['key'])) {
×
56
            throw new \Exception('Please specify property \'key\'');
×
57
        }
58

59
        $targetFieldName = (string)$cObj->stdWrapValue(
×
60
            'as',
×
61
            $processorConfiguration
×
62
        );
×
63

64
        $key = GeneralUtility::trimExplode('.', $processorConfiguration['key'], true);
×
65

66
        // Extract (nested) property
67
        do {
68
            $processedData = $processedData[array_shift($key)] ?? null;
×
69
        } while (count($key));
×
70

71
        return [
×
72
            $targetFieldName => $processedData,
×
73
        ];
×
74
    }
75
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc