Skip to content

Commit e505f8c

Browse files
committed
Supress full HTML output, add exception for swagger
1 parent 7fd0335 commit e505f8c

File tree

6 files changed

+62
-107
lines changed

6 files changed

+62
-107
lines changed

src/Plugin/CancelLayoutRendering.php

-49
This file was deleted.

src/Plugin/ForceNoIndex.php

-43
This file was deleted.

src/Plugin/PreventLayoutRendering.php

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
3+
namespace ReachDigital\BlankClassicFrontend\Plugin;
4+
5+
use Magento\Framework\App\Config\ScopeConfigInterface;
6+
use Magento\Framework\App\Request\Http as RequestHttp;
7+
use Magento\Framework\View\Result\Page;
8+
use Magento\Store\Model\ScopeInterface;
9+
10+
class PreventLayoutRendering
11+
{
12+
protected ScopeConfigInterface $scopeConfig;
13+
14+
const allowedRoutes = [
15+
'swagger',
16+
];
17+
private RequestHttp $request;
18+
19+
public function __construct (
20+
ScopeConfigInterface $scopeConfig,
21+
RequestHttp $request
22+
) {
23+
$this->scopeConfig = $scopeConfig;
24+
$this->request = $request;
25+
}
26+
27+
public function afterRenderResult(
28+
Page $subject,
29+
$result,
30+
$response
31+
) {
32+
$shouldBlankFrontend = $this->scopeConfig->isSetFlag("blank_classic_frontend/general/enabled", ScopeInterface::SCOPE_STORE);
33+
$shouldRedirect = $this->scopeConfig->isSetFlag("blank_classic_frontend/general/should_redirect", ScopeInterface::SCOPE_STORE);
34+
35+
if ($shouldBlankFrontend) {
36+
if ($this->routeIsAllowed()) {
37+
return $result;
38+
}
39+
/** @var \Magento\Framework\App\Response\Http $response */
40+
$response->clearBody();
41+
if ($shouldRedirect) {
42+
$customUrl = $this->scopeConfig->getValue('blank_classic_frontend/general/custom_redirect', ScopeInterface::SCOPE_STORE) ?? '';
43+
$baseUrl = $this->scopeConfig->getValue('web/secure/base_link_url', ScopeInterface::SCOPE_STORE);
44+
$response->setRedirect(strlen(trim($customUrl)) > 0 ? $customUrl : $baseUrl);
45+
}
46+
}
47+
48+
return $result;
49+
}
50+
51+
private function routeIsAllowed(): bool
52+
{
53+
return in_array($this->request->getRouteName(), self::allowedRoutes);
54+
}
55+
}

src/etc/adminhtml/system.xml

+1-6
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,7 @@
2020
<comment>Enables the module</comment>
2121
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
2222
</field>
23-
<field id="noindex_nofollow" translate="label" type="select" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
24-
<label>Block Indexing</label>
25-
<comment>When enabled, forces the robots meta tag to NOINDEX,NOFOLLOW</comment>
26-
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
27-
</field>
28-
<field id="should_redirect" translate="label" type="select" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
23+
<field id="should_redirect" translate="label" type="select" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
2924
<label>Redirect</label>
3025
<comment>When enabled, redirects requests on the classic frontend to the Secure Base Link URL (web/secure/base_link_url)</comment>
3126
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>

src/etc/di.xml

-9
This file was deleted.

src/etc/frontend/di.xml

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0"?>
2+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
3+
<type name="Magento\Framework\View\Result\Page">
4+
<plugin name="ReachDigitalPreventFrontendLayoutRendering" type="ReachDigital\BlankClassicFrontend\Plugin\PreventLayoutRendering"/>
5+
</type>
6+
</config>

0 commit comments

Comments
 (0)