Skip to content

Commit 8a8608f

Browse files
author
Bohdan Korablov
committed
Merge remote-tracking branch 'falcons/MAGETWO-61744' into MAGETWO-63936-2
2 parents 6b8d561 + a3aabea commit 8a8608f

File tree

22 files changed

+862
-13
lines changed

22 files changed

+862
-13
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,4 +141,12 @@
141141
<type name="Magento\Backend\Model\Menu\Builder">
142142
<plugin name="SetupMenuBuilder" type="Magento\Backend\Model\Setup\MenuBuilder" />
143143
</type>
144+
<type name="Magento\Config\Model\Config\Structure\ConcealInProductionConfigList">
145+
<arguments>
146+
<argument name="configs" xsi:type="array">
147+
<item name="dev" xsi:type="const">Magento\Config\Model\Config\Structure\ElementVisibilityInterface::HIDDEN</item>
148+
<item name="general/locale/code" xsi:type="const">Magento\Config\Model\Config\Structure\ElementVisibilityInterface::DISABLED</item>
149+
</argument>
150+
</arguments>
151+
</type>
144152
</config>

app/code/Magento/Config/Block/System/Config/Form.php

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Magento\Framework\App\DeploymentConfig;
1212
use Magento\Framework\App\ObjectManager;
1313
use Magento\Framework\DataObject;
14+
use Magento\Config\Model\Config\Structure\ElementVisibilityInterface;
1415

1516
/**
1617
* System config form block
@@ -113,6 +114,11 @@ class Form extends \Magento\Backend\Block\Widget\Form\Generic
113114
*/
114115
private $appConfig;
115116

117+
/**
118+
* @var ElementVisibilityInterface
119+
*/
120+
private $elementVisibility;
121+
116122
/**
117123
* @param \Magento\Backend\Block\Template\Context $context
118124
* @param \Magento\Framework\Registry $registry
@@ -355,7 +361,9 @@ protected function _initElement(
355361
$sharedClass = $this->_getSharedCssClass($field);
356362
$requiresClass = $this->_getRequiresCssClass($field, $fieldPrefix);
357363

358-
$isReadOnly = $this->getSettingChecker()->isReadOnly($path, $this->getScope(), $this->getStringScopeCode());
364+
$isReadOnly = $this->getElementVisibility()->isDisabled($field->getPath());
365+
$isReadOnly = $isReadOnly
366+
?: $this->getSettingChecker()->isReadOnly($path, $this->getScope(), $this->getStringScopeCode());
359367
$formField = $fieldset->addField(
360368
$elementId,
361369
$field->getType(),
@@ -805,4 +813,21 @@ private function getAppConfigDataValue($path)
805813
}
806814
return $data->getData($path);
807815
}
816+
817+
/**
818+
* Gets instance of ElementVisibilityInterface.
819+
*
820+
* @return ElementVisibilityInterface
821+
* @deprecated Added to not break backward compatibility of the constructor signature
822+
* by injecting the new dependency directly.
823+
* The method can be removed in a future major release, when constructor signature can be changed.
824+
*/
825+
public function getElementVisibility()
826+
{
827+
if (null === $this->elementVisibility) {
828+
$this->elementVisibility = ObjectManager::getInstance()->get(ElementVisibilityInterface::class);
829+
}
830+
831+
return $this->elementVisibility;
832+
}
808833
}

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
use Magento\Framework\App\Config\ScopeConfigInterface;
99
use Magento\Store\Model\StoreManagerInterface;
10+
use Magento\Framework\App\ObjectManager;
1011

1112
abstract class AbstractElement implements ElementInterface
1213
{
@@ -36,6 +37,11 @@ abstract class AbstractElement implements ElementInterface
3637
*/
3738
protected $moduleManager;
3839

40+
/**
41+
* @var ElementVisibilityInterface
42+
*/
43+
private $elementVisibility;
44+
3945
/**
4046
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
4147
* @param \Magento\Framework\Module\Manager $moduleManager
@@ -141,6 +147,10 @@ public function getAttribute($key)
141147
*/
142148
public function isVisible()
143149
{
150+
if ($this->getElementVisibility()->isHidden($this->getPath())) {
151+
return false;
152+
}
153+
144154
if (isset($this->_data['if_module_enabled']) &&
145155
!$this->moduleManager->isOutputEnabled($this->_data['if_module_enabled'])) {
146156
return false;
@@ -203,4 +213,21 @@ public function getPath($fieldPrefix = '')
203213
{
204214
return $this->_getPath($this->getId(), $fieldPrefix);
205215
}
216+
217+
/**
218+
* Get instance of ElementVisibilityInterface.
219+
*
220+
* @return ElementVisibilityInterface
221+
* @deprecated Added to not break backward compatibility of the constructor signature
222+
* by injecting the new dependency directly.
223+
* The method can be removed in a future major release, when constructor signature can be changed.
224+
*/
225+
public function getElementVisibility()
226+
{
227+
if (null === $this->elementVisibility) {
228+
$this->elementVisibility = ObjectManager::getInstance()->get(ElementVisibilityInterface::class);
229+
}
230+
231+
return $this->elementVisibility;
232+
}
206233
}
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
<?php
2+
/**
3+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Config\Model\Config\Structure;
7+
8+
use Magento\Framework\App\State;
9+
10+
/**
11+
* Defines status of visibility of form elements on Stores > Settings > Configuration page
12+
* in Admin Panel in Production mode.
13+
*/
14+
class ConcealInProductionConfigList implements ElementVisibilityInterface
15+
{
16+
/**
17+
* The list of form element paths with concrete visibility status.
18+
*
19+
* E.g.
20+
*
21+
* ```php
22+
* [
23+
* 'general/locale/code' => ElementVisibilityInterface::DISABLED,
24+
* 'general/country' => ElementVisibilityInterface::HIDDEN,
25+
* ];
26+
* ```
27+
*
28+
* It means that:
29+
* - field Locale (in group Locale Options in section General) will be disabled
30+
* - group Country Options (in section General) will be hidden
31+
*
32+
* @var array
33+
*/
34+
private $configs = [];
35+
36+
/**
37+
* The object that has information about the state of the system.
38+
*
39+
* @var State
40+
*/
41+
private $state;
42+
43+
/**
44+
* @param State $state The object that has information about the state of the system
45+
* @param array $configs The list of form element paths with concrete visibility status.
46+
*/
47+
public function __construct(State $state, array $configs = [])
48+
{
49+
$this->state = $state;
50+
$this->configs = $configs;
51+
}
52+
53+
/**
54+
* @inheritdoc
55+
*/
56+
public function isHidden($path)
57+
{
58+
$path = $this->normalizePath($path);
59+
return $this->state->getMode() === State::MODE_PRODUCTION
60+
&& !empty($this->configs[$path])
61+
&& $this->configs[$path] === static::HIDDEN;
62+
}
63+
64+
/**
65+
* @inheritdoc
66+
*/
67+
public function isDisabled($path)
68+
{
69+
$path = $this->normalizePath($path);
70+
if ($this->state->getMode() === State::MODE_PRODUCTION) {
71+
while (true) {
72+
if (!empty($this->configs[$path])) {
73+
return $this->configs[$path] === static::DISABLED;
74+
}
75+
76+
$position = strripos($path, '/');
77+
if ($position === false) {
78+
break;
79+
}
80+
$path = substr($path, 0, $position);
81+
}
82+
}
83+
84+
return false;
85+
}
86+
87+
/**
88+
* Returns normalized path.
89+
*
90+
* @param string $path The path to be normalized
91+
* @return string The normalized path
92+
*/
93+
private function normalizePath($path)
94+
{
95+
return trim($path, '/');
96+
}
97+
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<?php
2+
/**
3+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Config\Model\Config\Structure;
7+
8+
use Magento\Framework\Exception\ConfigurationMismatchException;
9+
10+
/**
11+
* Contains list of classes which implement ElementVisibilityInterface for
12+
* checking of visibility of form elements on Stores > Settings > Configuration page in Admin Panel.
13+
*/
14+
class ElementVisibilityComposite implements ElementVisibilityInterface
15+
{
16+
/**
17+
* List of objects which implements ElementVisibilityInterface for
18+
* checking of visibility of form elements on Configuration page.
19+
*
20+
* @var ElementVisibilityInterface[]
21+
*/
22+
private $visibility = [];
23+
24+
/**
25+
* @param ElementVisibilityInterface[] $visibility List of objects which define visibility status of form elements
26+
* under its own conditions.
27+
* @throws ConfigurationMismatchException It is thrown if some object from list $visibility
28+
* implements the wrong interface.
29+
*/
30+
public function __construct(array $visibility = [])
31+
{
32+
foreach ($visibility as $name => $item) {
33+
if (!$item instanceof ElementVisibilityInterface) {
34+
throw new ConfigurationMismatchException(
35+
__(
36+
'%1: Instance of %2 is expected, got %3 instead',
37+
$name,
38+
ElementVisibilityInterface::class,
39+
get_class($item)
40+
)
41+
);
42+
}
43+
}
44+
45+
$this->visibility = $visibility;
46+
}
47+
48+
/**
49+
* @inheritdoc
50+
*/
51+
public function isHidden($path)
52+
{
53+
foreach ($this->visibility as $element) {
54+
if ($element->isHidden($path)) {
55+
return true;
56+
}
57+
}
58+
59+
return false;
60+
}
61+
62+
/**
63+
* @inheritdoc
64+
*/
65+
public function isDisabled($path)
66+
{
67+
foreach ($this->visibility as $element) {
68+
if ($element->isDisabled($path)) {
69+
return true;
70+
}
71+
}
72+
73+
return false;
74+
}
75+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
/**
3+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Config\Model\Config\Structure;
7+
8+
/**
9+
* Checks visibility status of form elements on Stores > Settings > Configuration page in Admin Panel
10+
* by their paths in the system.xml structure.
11+
*/
12+
interface ElementVisibilityInterface
13+
{
14+
/**#@+
15+
* Constants of statuses for form elements.
16+
*/
17+
const HIDDEN = 'hidden';
18+
const DISABLED = 'disabled';
19+
/**#@-*/
20+
21+
/**
22+
* Check whether form element is disabled by path.
23+
*
24+
* @param string $path The path of form element in the system.xml structure
25+
* @return bool
26+
*/
27+
public function isDisabled($path);
28+
29+
/**
30+
* Check whether form element is hidden in form by path.
31+
*
32+
* @param string $path The path of form element in the system.xml structure
33+
* @return bool
34+
*/
35+
public function isHidden($path);
36+
}

0 commit comments

Comments
 (0)