-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from ho-nl/feature/supress-full-html
Suppress full HTML output, add exception for swagger
- Loading branch information
Showing
6 changed files
with
62 additions
and
107 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
namespace ReachDigital\BlankClassicFrontend\Plugin; | ||
|
||
use Magento\Framework\App\Config\ScopeConfigInterface; | ||
use Magento\Framework\App\Request\Http as RequestHttp; | ||
use Magento\Framework\View\Result\Page; | ||
use Magento\Store\Model\ScopeInterface; | ||
|
||
class PreventLayoutRendering | ||
{ | ||
protected ScopeConfigInterface $scopeConfig; | ||
|
||
const allowedRoutes = [ | ||
'swagger', | ||
]; | ||
private RequestHttp $request; | ||
|
||
public function __construct ( | ||
ScopeConfigInterface $scopeConfig, | ||
RequestHttp $request | ||
) { | ||
$this->scopeConfig = $scopeConfig; | ||
$this->request = $request; | ||
} | ||
|
||
public function afterRenderResult( | ||
Page $subject, | ||
$result, | ||
$response | ||
) { | ||
$shouldBlankFrontend = $this->scopeConfig->isSetFlag("blank_classic_frontend/general/enabled", ScopeInterface::SCOPE_STORE); | ||
$shouldRedirect = $this->scopeConfig->isSetFlag("blank_classic_frontend/general/should_redirect", ScopeInterface::SCOPE_STORE); | ||
|
||
if ($shouldBlankFrontend) { | ||
if ($this->routeIsAllowed()) { | ||
return $result; | ||
} | ||
/** @var \Magento\Framework\App\Response\Http $response */ | ||
$response->clearBody(); | ||
if ($shouldRedirect) { | ||
$customUrl = $this->scopeConfig->getValue('blank_classic_frontend/general/custom_redirect', ScopeInterface::SCOPE_STORE) ?? ''; | ||
$baseUrl = $this->scopeConfig->getValue('web/secure/base_link_url', ScopeInterface::SCOPE_STORE); | ||
$response->setRedirect(strlen(trim($customUrl)) > 0 ? $customUrl : $baseUrl); | ||
} | ||
} | ||
|
||
return $result; | ||
} | ||
|
||
private function routeIsAllowed(): bool | ||
{ | ||
return in_array($this->request->getRouteName(), self::allowedRoutes); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0"?> | ||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> | ||
<type name="Magento\Framework\View\Result\Page"> | ||
<plugin name="ReachDigitalPreventFrontendLayoutRendering" type="ReachDigital\BlankClassicFrontend\Plugin\PreventLayoutRendering"/> | ||
</type> | ||
</config> |