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

TYPO3-Headless / headless / 12065205662

28 Nov 2024 08:32AM UTC coverage: 72.782%. Remained the same
12065205662

push

github

web-flow
[BUGFIX] Don't render double slashes in file URLs (#796)

Without a frontendApiProxy in the site config, URLs to local files contain two slashes like www.mysite.org//fileadmin/my-image.jpg

1083 of 1488 relevant lines covered (72.78%)

8.4 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 Exception;
15
use TYPO3\CMS\Core\Utility\GeneralUtility;
16
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
17
use TYPO3\CMS\Frontend\ContentObject\DataProcessorInterface;
18

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

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

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

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

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

72
        return [
×
73
            $targetFieldName => $processedData,
×
74
        ];
×
75
    }
76
}
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