Skip to content

Commit 44e3fab

Browse files
committed
MAGETWO-91934: Unlock Locales Editing when SCD on Demand Mode is Enabled
1 parent ebbee92 commit 44e3fab

File tree

8 files changed

+727
-55
lines changed

8 files changed

+727
-55
lines changed

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
{
@@ -76,7 +77,7 @@ public function __construct(State $state, array $configs = [], array $exemptions
7677

7778
/**
7879
* @inheritdoc
79-
* @since 100.2.0
80+
* @deprecated
8081
*/
8182
public function isHidden($path)
8283
{
@@ -99,7 +100,7 @@ public function isHidden($path)
99100

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

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
/**
@@ -47,6 +52,8 @@ protected function setUp()
4752
* @param string $mageMode
4853
* @param bool $expectedResult
4954
* @dataProvider disabledDataProvider
55+
*
56+
* @deprecated
5057
*/
5158
public function testIsDisabled($path, $mageMode, $expectedResult)
5259
{
@@ -58,6 +65,8 @@ public function testIsDisabled($path, $mageMode, $expectedResult)
5865

5966
/**
6067
* @return array
68+
*
69+
* @deprecated
6170
*/
6271
public function disabledDataProvider()
6372
{
@@ -82,6 +91,8 @@ public function disabledDataProvider()
8291
* @param string $mageMode
8392
* @param bool $expectedResult
8493
* @dataProvider hiddenDataProvider
94+
*
95+
* @deprecated
8596
*/
8697
public function testIsHidden($path, $mageMode, $expectedResult)
8798
{
@@ -93,6 +104,8 @@ public function testIsHidden($path, $mageMode, $expectedResult)
93104

94105
/**
95106
* @return array
107+
*
108+
* @deprecated
96109
*/
97110
public function hiddenDataProvider()
98111
{

0 commit comments

Comments
 (0)