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

heimrichhannot / contao-encore-bundle / 24667931129

20 Apr 2026 01:00PM UTC coverage: 73.04% (-0.8%) from 73.813%
24667931129

push

github

web-flow
Support contao twig slot layouts (#34)

112 of 150 new or added lines in 11 files covered. (74.67%)

7 existing lines in 2 files now uncovered.

531 of 727 relevant lines covered (73.04%)

2.03 hits per line

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

93.33
/src/EntryPoint/EntryPointsBuilder.php
1
<?php
2

3
namespace HeimrichHannot\EncoreBundle\EntryPoint;
4

5
use Contao\LayoutModel;
6
use Contao\PageModel;
7
use Contao\StringUtil;
8
use HeimrichHannot\EncoreBundle\Asset\FrontendAsset;
9
use HeimrichHannot\EncoreBundle\Collection\EntryCollection;
10
use HeimrichHannot\EncoreBundle\Dca\EncoreEntriesSelectField;
11
use HeimrichHannot\UtilsBundle\Util\Utils;
12

13
class EntryPointsBuilder
14
{
15
    private ?PageModel $pageModel = null;
16
    private string $pageField = '';
17
    private ?LayoutModel $layout = null;
18
    private string $layoutField = '';
19
    private ?FrontendAsset $frontendAsset = null;
20

21
    private array $available = [];
22

23
    public function __construct(
24
        private readonly Utils $utils,
25
        private readonly EntryCollection $entryCollection,
26
    ) {
27
    }
2✔
28

29
    public function setPage(?PageModel $page, string $field = EncoreEntriesSelectField::NAME_DEFAULT): self
30
    {
31
        $this->pageModel = $page;
1✔
32
        $this->pageField = $field;
1✔
33

34
        return $this;
1✔
35
    }
36

37
    public function setLayout(?LayoutModel $layout, string $field = EncoreEntriesSelectField::NAME_DEFAULT): self
38
    {
39
        $this->layout = $layout;
1✔
40
        $this->layoutField = $field;
1✔
41

42
        return $this;
1✔
43
    }
44

45
    public function setFrontendAsset(?FrontendAsset $frontendAsset): self
46
    {
47
        $this->frontendAsset = $frontendAsset;
1✔
48

49
        return $this;
1✔
50
    }
51

52
    public function build(): EntryPoints
53
    {
54
        $entryPoints = new EntryPoints();
1✔
55
        $available = $this->entryCollection->getEntries();
1✔
56
        if ([] !== $available) {
1✔
57
            $available = array_combine(array_column($available, 'name'), $available);
1✔
58
        }
59
        $this->available = $available;
1✔
60

61
        if ($this->frontendAsset) {
1✔
62
            foreach ($this->frontendAsset->getActiveEntrypoints() as $entryPoint) {
1✔
63
                $this->addEntryPoint(
1✔
64
                    entryPoints: $entryPoints,
1✔
65
                    name: $entryPoint,
1✔
66
                    origin: FrontendAsset::class,
1✔
67
                );
1✔
68
            }
69
        }
70

71
        if ($this->pageModel && !$this->layout) {
1✔
NEW
72
            $this->pageModel->loadDetails();
×
NEW
73
            $layout = LayoutModel::findByPk($this->pageModel->layoutId ?? $this->pageModel->layout);
×
NEW
74
            if ($layout) {
×
NEW
75
                $this->setLayout($layout);
×
76
            }
77
        }
78

79
        if ($this->layout) {
1✔
80
            foreach (StringUtil::deserialize($this->layout->{$this->layoutField}, true) as $entrypoint) {
1✔
81
                $this->addEntryPoint(
1✔
82
                    entryPoints: $entryPoints,
1✔
83
                    name: $entrypoint['entry'] ?? '',
1✔
84
                    active: (bool) ($entrypoint['active'] ?? true),
1✔
85
                    origin: 'tl_layout.' . $this->layout->id,
1✔
86
                    extension: 'App',
1✔
87
                );
1✔
88
            }
89
        }
90

91
        if (null !== $this->pageModel) {
1✔
92
            $pages = $this->utils->model()->findParentsRecursively($this->pageModel, 'pid');
1✔
93
            $pages[] = $this->pageModel;
1✔
94

95
            foreach ($pages as $page) {
1✔
96
                foreach (StringUtil::deserialize($page->{$this->pageField}, true) as $entrypoint) {
1✔
97
                    $this->addEntryPoint(
1✔
98
                        entryPoints: $entryPoints,
1✔
99
                        name: $entrypoint['entry'] ?? '',
1✔
100
                        active: (bool) ($entrypoint['active'] ?? true),
1✔
101
                        origin: 'tl_page.' . $page->id,
1✔
102
                        extension: 'App',
1✔
103
                    );
1✔
104
                }
105
            }
106
        }
107

108
        return $entryPoints;
1✔
109
    }
110

111
    private function addEntryPoint(EntryPoints $entryPoints, string $name, bool $active = true, string $origin = '', string $extension = ''): void
112
    {
113
        if ('' === $name) {
1✔
114
            return;
1✔
115
        }
116

117
        if (!isset($this->available[$name])) {
1✔
118
            return;
1✔
119
        }
120

121
        $entryPoints->add(new EntryPoint(
1✔
122
            name: $name,
1✔
123
            active: $active,
1✔
124
            head: $this->available[$name]['head'] ?? false,
1✔
125
            requiresCss: (bool) ($this->available[$name]['requires_css'] ?? true),
1✔
126
            origin: $origin,
1✔
127
            extension: $extension,
1✔
128
        ));
1✔
129
    }
130
}
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

© 2026 Coveralls, Inc