Skip to content

Commit

Permalink
Bump version, add extra configs.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sophie Shanahan-Kluth committed Jun 18, 2020
1 parent 7852e16 commit d6ebe2e
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 26 deletions.
12 changes: 12 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
root = true

[*]
charset = utf-8
end_of_line = lf
indent_size = 4
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true

[*.md]
trim_trailing_whitespace = false
15 changes: 9 additions & 6 deletions Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,20 @@
use Magento\Framework\App\Helper\AbstractHelper;
use Magento\Store\Model\ScopeInterface;

class Data extends AbstractHelper{
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_frontend_as', ScopeInterface::SCOPE_WEBSITE
);
public function getConfigValue()
{
return [
'show_frontend_as' => $this->scopeConfig->getValue('admin/disable_frontend/show_frontend_as', ScopeInterface::SCOPE_WEBSITE),
'redirect_to' => $this->scopeConfig->getValue('admin/disable_frontend/redirect_to', ScopeInterface::SCOPE_WEBSITE),
];
}
}

}
14 changes: 8 additions & 6 deletions Model/Config/Source/Custom.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<?php

namespace FocusriteNovation\DisableFrontend\Model\Config\Source;

use Magento\Framework\Option\ArrayInterface;

class Custom implements \Magento\Framework\Option\ArrayInterface{
class Custom implements ArrayInterface {

/**
* Options for the admin config
Expand All @@ -12,11 +14,11 @@ class Custom implements \Magento\Framework\Option\ArrayInterface{
*/
public function toOptionArray()
{

return [
['value' => 0, 'label' => __('Blank page')],
['value' => 1, 'label' => __('Admin login')],
['value' => 2, 'label' => __('Specific URL')],
['value' => 'blank_page', 'label' => __('Blank page')],
['value' => 'admin_login', 'label' => __('Admin login')],
['value' => 'specific_url', 'label' => __('Specific URL')],
];
}
}

}
32 changes: 20 additions & 12 deletions Observer/DisableFrontend.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@ class DisableFrontend implements ObserverInterface {
* @var Magento\Framework\App\ActionFlag;
*/
protected $_actionFlag;

/**
* @var Magento\Framework\App\Response\RedirectInterface
*/
protected $redirect;

/**
* @var Magento\Backend\Helper\Data
*/
private $helperBackend;

/**
* @var FocusriteNovation\DisableFrontend\Helper\Data
*/
Expand All @@ -51,24 +51,32 @@ public function __construct(
$this->helperBackend = $helperBackend;
$this->disableFrontendHelper = $disableFrontendHelper;
}

/**
* Show an empty page(default) or redirect to Admin site.
* Depend in the config in
* Stores > Configuration > Advanced > Admin > Disable Frontend
* Show an empty page (default) or redirect to a given page.
*
* Config is set in Stores > Configuration > Advanced > Admin > Disable
* Frontend.
*
* @author Abel Bolanos Martinez <[email protected]>
* @param \Magento\Framework\Event\ObserverInterface $observer
* @return void
*/
public function execute(ObserverInterface $observer)
{
{
// Shows a blank page if all else fails.
$this->_actionFlag->set('', Action::FLAG_NO_DISPATCH, true);

if ($this->disableFrontendHelper->getConfigValue() === 1) {

$configValue = $this->disableFrontendHelper->getConfigValue();

if ($configValue['show_frontend_as'] === 'admin_login') {
// Redirect to admin.
$controller = $observer->getControllerAction();
$this->redirect->redirect($controller->getResponse(),$this->helperBackend->getHomePageUrl());
$this->redirect->redirect($controller->getResponse(), $this->helperBackend->getHomePageUrl());
}
elseif ($configValue['show_frontend_as'] === 'redirect_to') {
// Check that the URL is valid.
// Redirect to that URL.
}
}
}
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"php": ">=5.5"
},
"type": "magento2-module",
"version": "1.1.1",
"version": "1.2.0",
"license": [
"AGPL-3.0"
],
Expand Down
2 changes: 1 addition & 1 deletion etc/module.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="FocusriteNovation_DisableFrontend" setup_version="1.1.0">
<module name="FocusriteNovation_DisableFrontend" setup_version="1.2.0">
<sequence>
<module name="Magento_Store"/>
</sequence>
Expand Down

0 comments on commit d6ebe2e

Please sign in to comment.