Skip to content

Commit

Permalink
Merge pull request magento#2620 from magento-thunder/MAGETWO-92154
Browse files Browse the repository at this point in the history
Fixed issues:
- MAGETWO-92154: [Backport to 2.2] Unlock Locales Editing when SCD on Demand Mode is Enabled
  • Loading branch information
arhiopterecs authored May 31, 2018
2 parents 9d6930c + 3d42703 commit 1ce8c0a
Show file tree
Hide file tree
Showing 10 changed files with 683 additions and 64 deletions.
8 changes: 7 additions & 1 deletion app/code/Magento/Backend/etc/adminhtml/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,16 @@
<type name="Magento\Backend\Model\Menu\Builder">
<plugin name="SetupMenuBuilder" type="Magento\Backend\Model\Setup\MenuBuilder" />
</type>
<type name="Magento\Config\Model\Config\Structure\ConcealInProductionConfigList">
<type name="Magento\Config\Model\Config\Structure\ElementVisibility\ConcealInProduction">
<arguments>
<argument name="configs" xsi:type="array">
<item name="dev" xsi:type="const">Magento\Config\Model\Config\Structure\ElementVisibilityInterface::HIDDEN</item>
</argument>
</arguments>
</type>
<type name="Magento\Config\Model\Config\Structure\ElementVisibility\ConcealInProductionWithoutScdOnDemand">
<arguments>
<argument name="configs" xsi:type="array">
<item name="general/locale/code" xsi:type="const">Magento\Config\Model\Config\Structure\ElementVisibilityInterface::DISABLED</item>
</argument>
</arguments>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
* Defines status of visibility of form elements on Stores > Settings > Configuration page
* in Admin Panel in Production mode.
* @api
* @since 100.2.0
* @deprecated class location was changed
* @see \Magento\Config\Model\Config\Structure\ElementVisibility\ConcealInProduction
*/
class ConcealInProductionConfigList implements ElementVisibilityInterface
{
Expand Down Expand Up @@ -54,7 +55,7 @@ public function __construct(State $state, array $configs = [])

/**
* @inheritdoc
* @since 100.2.0
* @deprecated
*/
public function isHidden($path)
{
Expand All @@ -66,7 +67,7 @@ public function isHidden($path)

/**
* @inheritdoc
* @since 100.2.0
* @deprecated
*/
public function isDisabled($path)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Config\Model\Config\Structure\ElementVisibility;

use Magento\Config\Model\Config\Structure\ElementVisibilityInterface;
use Magento\Framework\App\State;

/**
* Defines status of visibility of form elements on Stores > Settings > Configuration page
* in Admin Panel in Production mode.
* @api
*/
class ConcealInProduction implements ElementVisibilityInterface
{
/**
* The list of form element paths with concrete visibility status.
*
* E.g.
*
* ```php
* [
* 'general/locale/code' => ElementVisibilityInterface::DISABLED,
* 'general/country' => ElementVisibilityInterface::HIDDEN,
* ];
* ```
*
* It means that:
* - field Locale (in group Locale Options in section General) will be disabled
* - group Country Options (in section General) will be hidden
*
* @var array
*/
private $configs = [];

/**
* The object that has information about the state of the system.
*
* @var State
*/
private $state;

/**
*
* The list of form element paths which ignore visibility status.
*
* E.g.
*
* ```php
* [
* 'general/country/default' => '',
* ];
* ```
*
* It means that:
* - field 'default' in group Country Options (in section General) will be showed, even if all group(section)
* will be hidden.
*
* @var array
*/
private $exemptions = [];

/**
* @param State $state The object that has information about the state of the system
* @param array $configs The list of form element paths with concrete visibility status.
* @param array $exemptions The list of form element paths which ignore visibility status.
*/
public function __construct(State $state, array $configs = [], array $exemptions = [])
{
$this->state = $state;
$this->configs = $configs;
$this->exemptions = $exemptions;
}

/**
* @inheritdoc
* @since 100.2.0
*/
public function isHidden($path)
{
$path = $this->normalizePath($path);
if ($this->state->getMode() === State::MODE_PRODUCTION
&& preg_match('/(?<group>(?<section>.*?)\/.*?)\/.*?/', $path, $match)) {
$group = $match['group'];
$section = $match['section'];
$exemptions = array_keys($this->exemptions);
$checkedItems = [];
foreach ([$path, $group, $section] as $itemPath) {
$checkedItems[] = $itemPath;
if (!empty($this->configs[$itemPath])) {
return $this->configs[$itemPath] === static::HIDDEN
&& empty(array_intersect($checkedItems, $exemptions));
}
}
}

return false;
}

/**
* @inheritdoc
* @since 100.2.0
*/
public function isDisabled($path)
{
$path = $this->normalizePath($path);
if ($this->state->getMode() === State::MODE_PRODUCTION) {
while (true) {
if (!empty($this->configs[$path])) {
return $this->configs[$path] === static::DISABLED;
}

$position = strripos($path, '/');
if ($position === false) {
break;
}
$path = substr($path, 0, $position);
}
}

return false;
}

/**
* Returns normalized path.
*
* @param string $path The path to be normalized
* @return string The normalized path
*/
private function normalizePath($path)
{
return trim($path, '/');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Config\Model\Config\Structure\ElementVisibility;

use Magento\Config\Model\Config\Structure\ElementVisibilityInterface;
use Magento\Framework\App\DeploymentConfig;
use Magento\Framework\Config\ConfigOptionsListConstants as Constants;

/**
* Defines status of visibility of form elements on Stores > Settings > Configuration page
* when Constants::CONFIG_PATH_SCD_ON_DEMAND_IN_PRODUCTION is enabled
* otherwise rule from Magento\Config\Model\Config\Structure\ElementVisibility\ConcealInProduction is used
* @see \Magento\Config\Model\Config\Structure\ElementVisibility\ConcealInProduction
*
* @api
*/
class ConcealInProductionWithoutScdOnDemand implements ElementVisibilityInterface
{
/**
* @var ConcealInProduction Element visibility rules in the Production mode
*/
private $concealInProduction;

/**
* @var DeploymentConfig The application deployment configuration
*/
private $deploymentConfig;

/**
* @param ConcealInProductionFactory $concealInProductionFactory
* @param DeploymentConfig $deploymentConfig Deployment configuration reader
* @param array $configs The list of form element paths with concrete visibility status.
* @param array $exemptions The list of form element paths which ignore visibility status.
*/
public function __construct(
ConcealInProductionFactory $concealInProductionFactory,
DeploymentConfig $deploymentConfig,
array $configs = [],
array $exemptions = []
) {
$this->concealInProduction = $concealInProductionFactory
->create(['configs' => $configs, 'exemptions' => $exemptions]);
$this->deploymentConfig = $deploymentConfig;
}

/**
* @inheritdoc
*/
public function isHidden($path): bool
{
if (!$this->deploymentConfig->getConfigData(Constants::CONFIG_PATH_SCD_ON_DEMAND_IN_PRODUCTION)) {
return $this->concealInProduction->isHidden($path);
}
return false;
}

/**
* @inheritdoc
*/
public function isDisabled($path): bool
{
if (!$this->deploymentConfig->getConfigData(Constants::CONFIG_PATH_SCD_ON_DEMAND_IN_PRODUCTION)) {
return $this->concealInProduction->isDisabled($path);
}
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
use Magento\Config\Model\Config\Structure\ConcealInProductionConfigList;
use Magento\Framework\App\State;

/**
* @deprecated Original class has changed the location
* @see \Magento\Config\Model\Config\Structure\ElementVisibility\ConcealInProduction
* @see \Magento\Config\Test\Unit\Model\Config\Structure\ElementVisibility\ConcealInProductionTest
*/
class ConcealInProductionConfigListTest extends \PHPUnit\Framework\TestCase
{
/**
Expand Down Expand Up @@ -43,6 +48,8 @@ protected function setUp()
* @param string $mageMode
* @param bool $expectedResult
* @dataProvider disabledDataProvider
*
* @deprecated
*/
public function testIsDisabled($path, $mageMode, $expectedResult)
{
Expand All @@ -54,6 +61,8 @@ public function testIsDisabled($path, $mageMode, $expectedResult)

/**
* @return array
*
* @deprecated
*/
public function disabledDataProvider()
{
Expand All @@ -78,6 +87,8 @@ public function disabledDataProvider()
* @param string $mageMode
* @param bool $expectedResult
* @dataProvider hiddenDataProvider
*
* @deprecated
*/
public function testIsHidden($path, $mageMode, $expectedResult)
{
Expand All @@ -89,6 +100,8 @@ public function testIsHidden($path, $mageMode, $expectedResult)

/**
* @return array
*
* @deprecated
*/
public function hiddenDataProvider()
{
Expand Down
Loading

0 comments on commit 1ce8c0a

Please sign in to comment.