Skip to content

Commit

Permalink
Merge pull request #13 from ankith-codilar/issue-1000
Browse files Browse the repository at this point in the history
#1000 making an abstraction so that root template doesn't be static a…
  • Loading branch information
alfredsgenkins authored Nov 19, 2020
2 parents a4e207a + 322fad4 commit 8e9c3c9
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
8 changes: 7 additions & 1 deletion src/Controller/Pwa.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,13 @@ public function execute()
$resultLayout->setStatusHeader($this->code, '1.1', $this->phrase);
$resultLayout->setHeader('X-Status', $this->phrase);
$resultLayout->setAction($this->type);

try{
$templateName = 'pwa-root';
$resultLayout->setRootTemplate($templateName);
} catch (\Exception $exception) {
throw new \Exception(__($templateName . ' template not found'));
}

return $resultLayout;
}

Expand Down
25 changes: 24 additions & 1 deletion src/View/Result/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ class Page extends ExtendedPage
* @var string;
*/
private $action;

/**
* @var array;
*/
private $rootTemplatePool;
/**
* Constructor
*
Expand All @@ -101,6 +106,7 @@ class Page extends ExtendedPage
* @param bool $isIsolated
* @param View\EntitySpecificHandlesList $entitySpecificHandlesList
* @param string $action
* @param array $rootTemplatePool
*
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
Expand All @@ -116,7 +122,8 @@ public function __construct(
$template,
$isIsolated = false,
View\EntitySpecificHandlesList $entitySpecificHandlesList = null,
$action = null
$action = null,
$rootTemplatePool = []
) {
parent::__construct(
$context,
Expand All @@ -132,6 +139,7 @@ public function __construct(
$entitySpecificHandlesList
);
$this->action = $action;
$this->rootTemplatePool = $rootTemplatePool;
}

/**
Expand Down Expand Up @@ -159,5 +167,20 @@ public function getAction()
{
return $this->action;
}

/**
* @param string $template
* @return Page
* @throws Framework\Exception\LocalizedException
*/
public function setRootTemplate($template)
{
if (in_array($template, array_keys($this->rootTemplatePool))) {
$this->template = $this->rootTemplatePool[$template];
} else {
throw new Framework\Exception\LocalizedException(__('Invalid root template specified'));
}
return $this;
}

}
7 changes: 7 additions & 0 deletions src/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,11 @@
</argument>
</arguments>
</virtualType>
<type name="ScandiPWA\Customization\View\Result\Page">
<arguments>
<argument name="rootTemplatePool" xsi:type="array">
<item name="pwa-root" xsi:type="string">Magento_Theme::scandipwa_root.phtml</item>
</argument>
</arguments>
</type>
</config>

0 comments on commit 8e9c3c9

Please sign in to comment.