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

heimrichhannot / contao-encore-bundle / 24667646096

20 Apr 2026 12:48PM UTC coverage: 73.003%. First build
24667646096

Pull #34

github

web-flow
Merge 7f9eaeea4 into 276699a73
Pull Request #34: Support contao twig slot layouts

111 of 149 new or added lines in 11 files covered. (74.5%)

530 of 726 relevant lines covered (73.0%)

2.03 hits per line

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

93.22
/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
        $available = array_combine(array_column($available, 'name'), $available);
1✔
57
        $this->available = $available;
1✔
58

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

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

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

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

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

106
        return $entryPoints;
1✔
107
    }
108

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

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

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