File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ <?php declare (strict_types=1 );
2+
3+ namespace Loki \Components \Layout ;
4+
5+ use Magento \Framework \View \LayoutInterface ;
6+
7+ class LayoutHandlerComposite
8+ {
9+ public function __construct (
10+ private readonly LayoutInterface $ layout ,
11+ private readonly array $ layoutHandlers = []
12+ ) {
13+ }
14+
15+ public function execute (array $ handles ): void
16+ {
17+ $ originalHandles = $ handles ;
18+ $ handles = $ this ->getHandles ($ handles );
19+ foreach ($ handles as $ handle ) {
20+ $ this ->layout ->getUpdate ()->addHandle ($ handle );
21+ }
22+
23+ foreach (array_diff ($ originalHandles , $ handles ) as $ handle ) {
24+ $ this ->layout ->getUpdate ()->removeHandle ($ handle );
25+ }
26+ }
27+
28+ public function getHandles (array $ handles ): array
29+ {
30+ foreach ($ this ->layoutHandlers as $ layoutHandler ) {
31+ if (false === $ layoutHandler instanceof LayoutHandlerInterface) {
32+ continue ;
33+ }
34+
35+ $ handles = $ layoutHandler ->get ($ handles );
36+ }
37+
38+ $ handles = array_unique ($ handles );
39+
40+ return $ handles ;
41+ }
42+ }
Original file line number Diff line number Diff line change 1+ <?php
2+ declare (strict_types=1 );
3+
4+ namespace Loki \Components \Layout ;
5+
6+ interface LayoutHandlerInterface
7+ {
8+ /**
9+ * @param $handles string[]
10+ * @return string[]
11+ */
12+ public function get (array $ handles ): array ;
13+ }
Original file line number Diff line number Diff line change 22
33namespace Loki \Components \Util \Controller ;
44
5+ use Loki \Components \Layout \LayoutHandlerComposite ;
56use Magento \Framework \View \LayoutInterface ;
67use Magento \Framework \View \Result \PageFactory as ResultPageFactory ;
78
89class LayoutLoader
910{
1011 public function __construct (
1112 private readonly ResultPageFactory $ resultPageFactory ,
13+ private readonly LayoutHandlerComposite $ layoutHandlerComposite
1214 ) {
1315 }
1416
1517 public function load (array $ handles = []): LayoutInterface
1618 {
19+ $ handles = $ this ->layoutHandlerComposite ->getHandles ($ handles );
1720 $ resultPage = $ this ->resultPageFactory ->create ();
1821
1922 if ($ handles !== []) {
Original file line number Diff line number Diff line change 22
33namespace Loki \Components \Util \Controller ;
44
5+ use Loki \Components \Layout \LayoutHandlerComposite ;
56use Loki \Components \Util \IdConvertor ;
67use Magento \Framework \Event \Manager as EventManager ;
78use Magento \Framework \View \Element \AbstractBlock ;
@@ -13,11 +14,16 @@ public function __construct(
1314 private readonly EventManager $ eventManager ,
1415 private readonly LayoutInterface $ layout ,
1516 private readonly IdConvertor $ idConvertor ,
17+ private readonly LayoutHandlerComposite $ layoutHandlerComposite ,
18+ private readonly LayoutLoader $ layoutLoader
1619 ) {
1720 }
1821
1922 public function render (LayoutInterface $ layout , array $ targetNames ): array
2023 {
24+ $ handles = $ this ->layoutHandlerComposite ->getHandles ($ layout ->getUpdate ()->getHandles ());
25+ $ layout = $ this ->layoutLoader ->load ($ handles );
26+
2127 return $ this ->renderBlocks ($ layout , $ this ->getTargetBlockNames ($ targetNames ));
2228 }
2329
You can’t perform that action at this time.
0 commit comments