Skip to content

Commit

Permalink
Merge pull request #3 from ho-nl/feature/supress-full-html
Browse files Browse the repository at this point in the history
Suppress full HTML output, add exception for swagger
  • Loading branch information
hnsr authored Jun 14, 2024
2 parents 7fd0335 + e505f8c commit aacd77b
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 107 deletions.
49 changes: 0 additions & 49 deletions src/Plugin/CancelLayoutRendering.php

This file was deleted.

43 changes: 0 additions & 43 deletions src/Plugin/ForceNoIndex.php

This file was deleted.

55 changes: 55 additions & 0 deletions src/Plugin/PreventLayoutRendering.php
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);
}
}
7 changes: 1 addition & 6 deletions src/etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,7 @@
<comment>Enables the module</comment>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
<field id="noindex_nofollow" translate="label" type="select" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Block Indexing</label>
<comment>When enabled, forces the robots meta tag to NOINDEX,NOFOLLOW</comment>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
<field id="should_redirect" translate="label" type="select" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
<field id="should_redirect" translate="label" type="select" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Redirect</label>
<comment>When enabled, redirects requests on the classic frontend to the Secure Base Link URL (web/secure/base_link_url)</comment>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
Expand Down
9 changes: 0 additions & 9 deletions src/etc/di.xml

This file was deleted.

6 changes: 6 additions & 0 deletions src/etc/frontend/di.xml
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>

0 comments on commit aacd77b

Please sign in to comment.