Skip to content

Commit eaa8525

Browse files
authored
Merge pull request #2613 from magento-thunder/MAGETWO-91934
Fixed issues: - MAGETWO-91934: Unlock Locales Editing when SCD on Demand Mode is Enabled
2 parents 2cbe1a6 + ad32287 commit eaa8525

File tree

10 files changed

+674
-64
lines changed

10 files changed

+674
-64
lines changed

app/code/Magento/Backend/etc/adminhtml/di.xml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,16 @@
139139
<type name="Magento\Backend\Model\Menu\Builder">
140140
<plugin name="SetupMenuBuilder" type="Magento\Backend\Model\Setup\MenuBuilder" />
141141
</type>
142-
<type name="Magento\Config\Model\Config\Structure\ConcealInProductionConfigList">
142+
<type name="Magento\Config\Model\Config\Structure\ElementVisibility\ConcealInProduction">
143143
<arguments>
144144
<argument name="configs" xsi:type="array">
145145
<item name="dev" xsi:type="const">Magento\Config\Model\Config\Structure\ElementVisibilityInterface::HIDDEN</item>
146+
</argument>
147+
</arguments>
148+
</type>
149+
<type name="Magento\Config\Model\Config\Structure\ElementVisibility\ConcealInProductionWithoutScdOnDemand">
150+
<arguments>
151+
<argument name="configs" xsi:type="array">
146152
<item name="general/locale/code" xsi:type="const">Magento\Config\Model\Config\Structure\ElementVisibilityInterface::DISABLED</item>
147153
</argument>
148154
</arguments>

app/code/Magento/Config/Model/Config/Structure/ConcealInProductionConfigList.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
* Defines status of visibility of form elements on Stores > Settings > Configuration page
1212
* in Admin Panel in Production mode.
1313
* @api
14-
* @since 100.2.0
14+
* @deprecated class location was changed
15+
* @see \Magento\Config\Model\Config\Structure\ElementVisibility\ConcealInProduction
1516
*/
1617
class ConcealInProductionConfigList implements ElementVisibilityInterface
1718
{
@@ -54,7 +55,7 @@ public function __construct(State $state, array $configs = [])
5455

5556
/**
5657
* @inheritdoc
57-
* @since 100.2.0
58+
* @deprecated
5859
*/
5960
public function isHidden($path)
6061
{
@@ -67,7 +68,7 @@ public function isHidden($path)
6768

6869
/**
6970
* @inheritdoc
70-
* @since 100.2.0
71+
* @deprecated
7172
*/
7273
public function isDisabled($path)
7374
{
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Config\Model\Config\Structure\ElementVisibility;
9+
10+
use Magento\Config\Model\Config\Structure\ElementVisibilityInterface;
11+
use Magento\Framework\App\State;
12+
13+
/**
14+
* Defines status of visibility of form elements on Stores > Settings > Configuration page
15+
* in Admin Panel in Production mode.
16+
* @api
17+
*/
18+
class ConcealInProduction implements ElementVisibilityInterface
19+
{
20+
/**
21+
* The list of form element paths with concrete visibility status.
22+
*
23+
* E.g.
24+
*
25+
* ```php
26+
* [
27+
* 'general/locale/code' => ElementVisibilityInterface::DISABLED,
28+
* 'general/country' => ElementVisibilityInterface::HIDDEN,
29+
* ];
30+
* ```
31+
*
32+
* It means that:
33+
* - field Locale (in group Locale Options in section General) will be disabled
34+
* - group Country Options (in section General) will be hidden
35+
*
36+
* @var array
37+
*/
38+
private $configs = [];
39+
40+
/**
41+
* The object that has information about the state of the system.
42+
*
43+
* @var State
44+
*/
45+
private $state;
46+
47+
/**
48+
*
49+
* The list of form element paths which ignore visibility status.
50+
*
51+
* E.g.
52+
*
53+
* ```php
54+
* [
55+
* 'general/country/default' => '',
56+
* ];
57+
* ```
58+
*
59+
* It means that:
60+
* - field 'default' in group Country Options (in section General) will be showed, even if all group(section)
61+
* will be hidden.
62+
*
63+
* @var array
64+
*/
65+
private $exemptions = [];
66+
67+
/**
68+
* @param State $state The object that has information about the state of the system
69+
* @param array $configs The list of form element paths with concrete visibility status.
70+
* @param array $exemptions The list of form element paths which ignore visibility status.
71+
*/
72+
public function __construct(State $state, array $configs = [], array $exemptions = [])
73+
{
74+
$this->state = $state;
75+
$this->configs = $configs;
76+
$this->exemptions = $exemptions;
77+
}
78+
79+
/**
80+
* @inheritdoc
81+
* @since 100.2.0
82+
*/
83+
public function isHidden($path)
84+
{
85+
$path = $this->normalizePath($path);
86+
if ($this->state->getMode() === State::MODE_PRODUCTION
87+
&& preg_match('/(?<group>(?<section>.*?)\/.*?)\/.*?/', $path, $match)) {
88+
$group = $match['group'];
89+
$section = $match['section'];
90+
$exemptions = array_keys($this->exemptions);
91+
$checkedItems = [];
92+
foreach ([$path, $group, $section] as $itemPath) {
93+
$checkedItems[] = $itemPath;
94+
if (!empty($this->configs[$itemPath])) {
95+
return $this->configs[$itemPath] === static::HIDDEN
96+
&& empty(array_intersect($checkedItems, $exemptions));
97+
}
98+
}
99+
}
100+
101+
return false;
102+
}
103+
104+
/**
105+
* @inheritdoc
106+
* @since 100.2.0
107+
*/
108+
public function isDisabled($path)
109+
{
110+
$path = $this->normalizePath($path);
111+
if ($this->state->getMode() === State::MODE_PRODUCTION) {
112+
while (true) {
113+
if (!empty($this->configs[$path])) {
114+
return $this->configs[$path] === static::DISABLED;
115+
}
116+
117+
$position = strripos($path, '/');
118+
if ($position === false) {
119+
break;
120+
}
121+
$path = substr($path, 0, $position);
122+
}
123+
}
124+
125+
return false;
126+
}
127+
128+
/**
129+
* Returns normalized path.
130+
*
131+
* @param string $path The path to be normalized
132+
* @return string The normalized path
133+
*/
134+
private function normalizePath($path)
135+
{
136+
return trim($path, '/');
137+
}
138+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Config\Model\Config\Structure\ElementVisibility;
9+
10+
use Magento\Config\Model\Config\Structure\ElementVisibilityInterface;
11+
use Magento\Framework\App\DeploymentConfig;
12+
use Magento\Framework\Config\ConfigOptionsListConstants as Constants;
13+
14+
/**
15+
* Defines status of visibility of form elements on Stores > Settings > Configuration page
16+
* when Constants::CONFIG_PATH_SCD_ON_DEMAND_IN_PRODUCTION is enabled
17+
* otherwise rule from Magento\Config\Model\Config\Structure\ElementVisibility\ConcealInProduction is used
18+
* @see \Magento\Config\Model\Config\Structure\ElementVisibility\ConcealInProduction
19+
*
20+
* @api
21+
*/
22+
class ConcealInProductionWithoutScdOnDemand implements ElementVisibilityInterface
23+
{
24+
/**
25+
* @var ConcealInProduction Element visibility rules in the Production mode
26+
*/
27+
private $concealInProduction;
28+
29+
/**
30+
* @var DeploymentConfig The application deployment configuration
31+
*/
32+
private $deploymentConfig;
33+
34+
/**
35+
* @param ConcealInProductionFactory $concealInProductionFactory
36+
* @param DeploymentConfig $deploymentConfig Deployment configuration reader
37+
* @param array $configs The list of form element paths with concrete visibility status.
38+
* @param array $exemptions The list of form element paths which ignore visibility status.
39+
*/
40+
public function __construct(
41+
ConcealInProductionFactory $concealInProductionFactory,
42+
DeploymentConfig $deploymentConfig,
43+
array $configs = [],
44+
array $exemptions = []
45+
) {
46+
$this->concealInProduction = $concealInProductionFactory
47+
->create(['configs' => $configs, 'exemptions' => $exemptions]);
48+
$this->deploymentConfig = $deploymentConfig;
49+
}
50+
51+
/**
52+
* @inheritdoc
53+
*/
54+
public function isHidden($path): bool
55+
{
56+
if (!$this->deploymentConfig->getConfigData(Constants::CONFIG_PATH_SCD_ON_DEMAND_IN_PRODUCTION)) {
57+
return $this->concealInProduction->isHidden($path);
58+
}
59+
return false;
60+
}
61+
62+
/**
63+
* @inheritdoc
64+
*/
65+
public function isDisabled($path): bool
66+
{
67+
if (!$this->deploymentConfig->getConfigData(Constants::CONFIG_PATH_SCD_ON_DEMAND_IN_PRODUCTION)) {
68+
return $this->concealInProduction->isDisabled($path);
69+
}
70+
return false;
71+
}
72+
}

app/code/Magento/Config/Test/Unit/Model/Config/Structure/ConcealInProductionConfigListTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@
88
use Magento\Config\Model\Config\Structure\ConcealInProductionConfigList;
99
use Magento\Framework\App\State;
1010

11+
/**
12+
* @deprecated Original class has changed the location
13+
* @see \Magento\Config\Model\Config\Structure\ElementVisibility\ConcealInProduction
14+
* @see \Magento\Config\Test\Unit\Model\Config\Structure\ElementVisibility\ConcealInProductionTest
15+
*/
1116
class ConcealInProductionConfigListTest extends \PHPUnit\Framework\TestCase
1217
{
1318
/**
@@ -43,6 +48,8 @@ protected function setUp()
4348
* @param string $mageMode
4449
* @param bool $expectedResult
4550
* @dataProvider disabledDataProvider
51+
*
52+
* @deprecated
4653
*/
4754
public function testIsDisabled($path, $mageMode, $expectedResult)
4855
{
@@ -54,6 +61,8 @@ public function testIsDisabled($path, $mageMode, $expectedResult)
5461

5562
/**
5663
* @return array
64+
*
65+
* @deprecated
5766
*/
5867
public function disabledDataProvider()
5968
{
@@ -78,6 +87,8 @@ public function disabledDataProvider()
7887
* @param string $mageMode
7988
* @param bool $expectedResult
8089
* @dataProvider hiddenDataProvider
90+
*
91+
* @deprecated
8192
*/
8293
public function testIsHidden($path, $mageMode, $expectedResult)
8394
{
@@ -89,6 +100,8 @@ public function testIsHidden($path, $mageMode, $expectedResult)
89100

90101
/**
91102
* @return array
103+
*
104+
* @deprecated
92105
*/
93106
public function hiddenDataProvider()
94107
{

0 commit comments

Comments
 (0)