forked from abelbm/magento2-disable-frontend
-
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.
- Loading branch information
Showing
6 changed files
with
87 additions
and
19 deletions.
There are no files selected for viewing
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,21 @@ | ||
<?php | ||
|
||
namespace Abelbm\DisableFrontend\Helper; | ||
|
||
use Magento\Framework\App\Helper\AbstractHelper; | ||
use Magento\Store\Model\ScopeInterface; | ||
|
||
class Data extends AbstractHelper{ | ||
|
||
/** | ||
* Get value from config | ||
* | ||
* @author Abel Bolanos Martinez <[email protected]> | ||
* @return mixed | ||
*/ | ||
public function getConfigValue() { | ||
return $this->scopeConfig->getValue( | ||
'admin/disable_frontend/show_as_frontend', ScopeInterface::SCOPE_WEBSITE | ||
); | ||
} | ||
} |
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,21 @@ | ||
<?php | ||
namespace Abelbm\DisableFrontend\Model\Config\Source; | ||
|
||
|
||
class Custom implements \Magento\Framework\Option\ArrayInterface{ | ||
|
||
/** | ||
* Options for the admin config | ||
* | ||
* @author Abel Bolanos Martinez <[email protected]> | ||
* @return array | ||
*/ | ||
public function toOptionArray() | ||
{ | ||
|
||
return [ | ||
['value' => 0, 'label' => __('Blank Page')], | ||
['value' => 1, 'label' => __('Admin')], | ||
]; | ||
} | ||
} |
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 |
---|---|---|
@@ -1,49 +1,61 @@ | ||
<?php | ||
namespace Abelbm\DisableFrontend\Observer; | ||
use Magento\Framework\Event\ObserverInterface; | ||
use Magento\Framework\App\ActionFlag; | ||
use Magento\Framework\App\Response\RedirectInterface; | ||
use Magento\Backend\Helper\Data; | ||
use Abelbm\DisableFrontend\Helper\Data as DisableFrontendHelper; | ||
|
||
class DisableFrontend implements ObserverInterface{ | ||
|
||
protected $_actionFlag; | ||
protected $redirect; | ||
private $HelperBackend; | ||
private $helperBackend; | ||
private $logger; | ||
|
||
private $disableFrontendHelper; | ||
|
||
/** | ||
* | ||
* @author Abel Bolanos Martinez <[email protected]> | ||
* @param \Magento\Framework\App\ActionFlag $actionFlag | ||
* @param \Magento\Framework\Message\ManagerInterface $messageManager | ||
* @param \Magento\Framework\App\Response\RedirectInterface $redirect | ||
* @param \Magento\Backend\Helper\Data $HelperBackend | ||
* DisableFrontend constructor. | ||
* | ||
* @author Abel Bolanos Martinez <[email protected]> | ||
* @param ActionFlag $actionFlag | ||
* @param RedirectInterface $redirect | ||
* @param Data $helperBackend | ||
* @param DisableFrontendHelper $disableFrontendHelper | ||
* @param \Psr\Log\LoggerInterface $logger | ||
*/ | ||
public function __construct( | ||
\Magento\Framework\App\ActionFlag $actionFlag, | ||
\Magento\Framework\App\Response\RedirectInterface $redirect, | ||
\Magento\Backend\Helper\Data $HelperBackend, | ||
ActionFlag $actionFlag, | ||
RedirectInterface $redirect, | ||
Data $helperBackend, | ||
DisableFrontendHelper $disableFrontendHelper, | ||
\Psr\Log\LoggerInterface $logger | ||
) { | ||
$this->_actionFlag = $actionFlag; | ||
$this->redirect = $redirect; | ||
$this->HelperBackend = $HelperBackend; | ||
$this->helperBackend = $helperBackend; | ||
$this->logger = $logger; | ||
$this->disableFrontendHelper = $disableFrontendHelper; | ||
} | ||
|
||
/** | ||
* Show an empty page(default) or redirect to Admin site. | ||
* Depend in the config in | ||
* Stores > Configuration > Advanced > Admin > Disable Frontend | ||
* | ||
* @author Abel Bolanos Martinez <[email protected]> | ||
* @param \Magento\Framework\Event\Observer $observer | ||
* @return void | ||
*/ | ||
public function execute(\Magento\Framework\Event\Observer $observer){ | ||
//$this->logger->info('TEST LOGGER'); | ||
|
||
//$this->logger->info('TEST'); | ||
|
||
$this->_actionFlag->set('', \Magento\Framework\App\Action\Action::FLAG_NO_DISPATCH, true); | ||
|
||
//custom redirect | ||
//$controller = $observer->getControllerAction(); | ||
//$this->redirect->redirect($controller->getResponse(),$this->HelperBackend->getHomePageUrl()); | ||
if($this->disableFrontendHelper->getConfigValue()){//redirect to Admin | ||
$controller = $observer->getControllerAction(); | ||
$this->redirect->redirect($controller->getResponse(),$this->helperBackend->getHomePageUrl()); | ||
} | ||
} | ||
} |
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 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,14 @@ | ||
<?xml version="1.0"?> | ||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd"> | ||
<system> | ||
<section id="admin"> | ||
<group id="disable_frontend" translate="label" type="text" sortOrder="9999" showInDefault="1" showInWebsite="0" showInStore="0"> | ||
<label>Disable Frontend</label> | ||
<field id="show_as_frontend" translate="label" type="select" sortOrder="1" showInDefault="1" showInWebsite="0" showInStore="0"> | ||
<label>Show frontend as</label> | ||
<source_model>Abelbm\DisableFrontend\Model\Config\Source\Custom</source_model> | ||
</field> | ||
</group> | ||
</section> | ||
</system> | ||
</config> |
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