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

sulu / SuluContentBundle / 11978668947

22 Nov 2024 07:11PM UTC coverage: 97.052% (-2.9%) from 100.0%
11978668947

Pull #271

github

web-flow
Merge 85d51e611 into a23a5b050
Pull Request #271: Draft: Base implementation of website content resolving

268 of 353 new or added lines in 17 files covered. (75.92%)

2798 of 2883 relevant lines covered (97.05%)

10.44 hits per line

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

96.15
/Content/Application/PropertyResolver/Resolver/TeaserSelectionPropertyResolver.php
1
<?php
2

3
declare(strict_types=1);
4

5
/*
6
 * This file is part of Sulu.
7
 *
8
 * (c) Sulu GmbH
9
 *
10
 * This source file is subject to the MIT license that is bundled
11
 * with this source code in the file LICENSE.
12
 */
13

14
namespace Sulu\Bundle\ContentBundle\Content\Application\PropertyResolver\Resolver;
15

16
use Sulu\Bundle\ContentBundle\Content\Application\ContentResolver\Value\ContentView;
17
use Sulu\Bundle\ContentBundle\Content\Application\ResourceLoader\Loader\TeaserResourceLoader;
18
use Sulu\Bundle\PageBundle\Teaser\Teaser;
19

20
class TeaserSelectionPropertyResolver implements PropertyResolverInterface
21
{
22
    /**
23
     * @param mixed[] $data
24
     * @param mixed[] $params
25
     */
26
    public function resolve(mixed $data, string $locale, array $params = []): ContentView
27
    {
28
        $returnedParams = ['presentsAs' => $data['presentsAs'] ?? null, ...$params];
5✔
29
        unset($returnedParams['metadata']);
5✔
30

31
        if (
32
            !\is_array($data)
5✔
33
            || !\array_key_exists('items', $data)
5✔
34
            || !\is_array($data['items'])
5✔
35
        ) {
36
            return ContentView::create($data, $returnedParams);
2✔
37
        }
38

39
        /** @var string $resourceLoaderKey */
40
        $resourceLoaderKey = $params['resourceLoader'] ?? TeaserResourceLoader::getKey();
3✔
41

42
        $contentViews = [];
3✔
43
        foreach ($data['items'] as $item) {
3✔
44
            if (!\is_array($item) || !\array_key_exists('id', $item) || !\array_key_exists('type', $item)) {
3✔
NEW
45
                continue;
×
46
            }
47
            $type = $item['type'];
3✔
48
            $id = $item['id'];
3✔
49

50
            $contentViews[] = ContentView::createResolvable(
3✔
51
                $type . '::' . $id,
3✔
52
                $resourceLoaderKey,
3✔
53
                [
3✔
54
                    'id' => $id,
3✔
55
                    'type' => $type,
3✔
56
                ],
3✔
57
                static function(Teaser $resource) use ($item) {
3✔
58
                    return $resource->merge($item);
1✔
59
                }
3✔
60
            );
3✔
61
        }
62

63
        return ContentView::create($contentViews, $returnedParams);
3✔
64
    }
65

66
    public static function getType(): string
67
    {
68
        return 'teaser_selection';
1✔
69
    }
70
}
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