Skip to content

Commit 8e9c3c9

Browse files
Merge pull request #13 from ankith-codilar/issue-1000
#1000 making an abstraction so that root template doesn't be static a…
2 parents a4e207a + 322fad4 commit 8e9c3c9

File tree

3 files changed

+38
-2
lines changed

3 files changed

+38
-2
lines changed

src/Controller/Pwa.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,13 @@ public function execute()
9898
$resultLayout->setStatusHeader($this->code, '1.1', $this->phrase);
9999
$resultLayout->setHeader('X-Status', $this->phrase);
100100
$resultLayout->setAction($this->type);
101-
101+
try{
102+
$templateName = 'pwa-root';
103+
$resultLayout->setRootTemplate($templateName);
104+
} catch (\Exception $exception) {
105+
throw new \Exception(__($templateName . ' template not found'));
106+
}
107+
102108
return $resultLayout;
103109
}
104110

src/View/Result/Page.php

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,11 @@ class Page extends ExtendedPage
8686
* @var string;
8787
*/
8888
private $action;
89+
90+
/**
91+
* @var array;
92+
*/
93+
private $rootTemplatePool;
8994
/**
9095
* Constructor
9196
*
@@ -101,6 +106,7 @@ class Page extends ExtendedPage
101106
* @param bool $isIsolated
102107
* @param View\EntitySpecificHandlesList $entitySpecificHandlesList
103108
* @param string $action
109+
* @param array $rootTemplatePool
104110
*
105111
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
106112
*/
@@ -116,7 +122,8 @@ public function __construct(
116122
$template,
117123
$isIsolated = false,
118124
View\EntitySpecificHandlesList $entitySpecificHandlesList = null,
119-
$action = null
125+
$action = null,
126+
$rootTemplatePool = []
120127
) {
121128
parent::__construct(
122129
$context,
@@ -132,6 +139,7 @@ public function __construct(
132139
$entitySpecificHandlesList
133140
);
134141
$this->action = $action;
142+
$this->rootTemplatePool = $rootTemplatePool;
135143
}
136144

137145
/**
@@ -159,5 +167,20 @@ public function getAction()
159167
{
160168
return $this->action;
161169
}
170+
171+
/**
172+
* @param string $template
173+
* @return Page
174+
* @throws Framework\Exception\LocalizedException
175+
*/
176+
public function setRootTemplate($template)
177+
{
178+
if (in_array($template, array_keys($this->rootTemplatePool))) {
179+
$this->template = $this->rootTemplatePool[$template];
180+
} else {
181+
throw new Framework\Exception\LocalizedException(__('Invalid root template specified'));
182+
}
183+
return $this;
184+
}
162185

163186
}

src/etc/di.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,11 @@
3737
</argument>
3838
</arguments>
3939
</virtualType>
40+
<type name="ScandiPWA\Customization\View\Result\Page">
41+
<arguments>
42+
<argument name="rootTemplatePool" xsi:type="array">
43+
<item name="pwa-root" xsi:type="string">Magento_Theme::scandipwa_root.phtml</item>
44+
</argument>
45+
</arguments>
46+
</type>
4047
</config>

0 commit comments

Comments
 (0)