Skip to content

Commit 1fbf992

Browse files
author
Oleksii Korshenko
committed
Merge branch 'MAGETWO-64313-PR-8373' into develop-prs
2 parents 7858c6e + 2e12195 commit 1fbf992

File tree

90 files changed

+4583
-119
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+4583
-119
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/Catalog/view/frontend/templates/product/view/attributes.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
?>
1515
<?php
1616
$_helper = $this->helper('Magento\Catalog\Helper\Output');
17-
$_product = $block->getProduct()
17+
$_product = $block->getProduct();
1818
?>
1919
<?php if ($_additional = $block->getAdditionalData()): ?>
2020
<div class="additional-attributes-wrapper table-wrapper">
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
<?php
2+
/**
3+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Config\App\Config\Source;
7+
8+
use Magento\Framework\App\Config\ConfigSourceInterface;
9+
use Magento\Framework\DataObject;
10+
use Magento\Config\Model\Placeholder\PlaceholderFactory;
11+
use Magento\Config\Model\Placeholder\PlaceholderInterface;
12+
use Magento\Framework\Stdlib\ArrayManager;
13+
14+
/**
15+
* Class for retrieving configurations from environment variables.
16+
*/
17+
class EnvironmentConfigSource implements ConfigSourceInterface
18+
{
19+
/**
20+
* Library for working with arrays.
21+
*
22+
* @var ArrayManager
23+
*/
24+
private $arrayManager;
25+
26+
/**
27+
* Object for working with placeholders for environment variables.
28+
*
29+
* @var PlaceholderInterface
30+
*/
31+
private $placeholder;
32+
33+
/**
34+
* @param ArrayManager $arrayManager
35+
* @param PlaceholderFactory $placeholderFactory
36+
*/
37+
public function __construct(
38+
ArrayManager $arrayManager,
39+
PlaceholderFactory $placeholderFactory
40+
) {
41+
$this->arrayManager = $arrayManager;
42+
$this->placeholder = $placeholderFactory->create(PlaceholderFactory::TYPE_ENVIRONMENT);
43+
}
44+
45+
/**
46+
* @inheritdoc
47+
*/
48+
public function get($path = '')
49+
{
50+
$data = new DataObject($this->loadConfig());
51+
return $data->getData($path) ?: [];
52+
}
53+
54+
/**
55+
* Loads config from environment variables.
56+
*
57+
* @return array
58+
*/
59+
private function loadConfig()
60+
{
61+
$config = [];
62+
63+
$environmentVariables = $_ENV;
64+
65+
foreach ($environmentVariables as $template => $value) {
66+
if (!$this->placeholder->isApplicable($template)) {
67+
continue;
68+
}
69+
70+
$config = $this->arrayManager->set(
71+
$this->placeholder->restore($template),
72+
$config,
73+
$value
74+
);
75+
}
76+
77+
return $config;
78+
}
79+
}

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

Lines changed: 28 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,14 @@ class Form extends \Magento\Backend\Block\Widget\Form\Generic
113114
*/
114115
private $appConfig;
115116

117+
/**
118+
* Checks visibility status of form elements on Stores > Settings > Configuration page in Admin Panel
119+
* by their paths in the system.xml structure.
120+
*
121+
* @var ElementVisibilityInterface
122+
*/
123+
private $elementVisibility;
124+
116125
/**
117126
* @param \Magento\Backend\Block\Template\Context $context
118127
* @param \Magento\Framework\Registry $registry
@@ -355,7 +364,8 @@ protected function _initElement(
355364
$sharedClass = $this->_getSharedCssClass($field);
356365
$requiresClass = $this->_getRequiresCssClass($field, $fieldPrefix);
357366

358-
$isReadOnly = $this->getSettingChecker()->isReadOnly($path, $this->getScope(), $this->getStringScopeCode());
367+
$isReadOnly = $this->getElementVisibility()->isDisabled($field->getPath())
368+
?: $this->getSettingChecker()->isReadOnly($path, $this->getScope(), $this->getStringScopeCode());
359369
$formField = $fieldset->addField(
360370
$elementId,
361371
$field->getType(),
@@ -805,4 +815,21 @@ private function getAppConfigDataValue($path)
805815
}
806816
return $data->getData($path);
807817
}
818+
819+
/**
820+
* Gets instance of ElementVisibilityInterface.
821+
*
822+
* @return ElementVisibilityInterface
823+
* @deprecated Added to not break backward compatibility of the constructor signature
824+
* by injecting the new dependency directly.
825+
* The method can be removed in a future major release, when constructor signature can be changed.
826+
*/
827+
public function getElementVisibility()
828+
{
829+
if (null === $this->elementVisibility) {
830+
$this->elementVisibility = ObjectManager::getInstance()->get(ElementVisibilityInterface::class);
831+
}
832+
833+
return $this->elementVisibility;
834+
}
808835
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
<?php
2+
/**
3+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Config\Console\Command\ConfigSet;
7+
8+
use Magento\Config\Console\Command\ConfigSetCommand;
9+
use Magento\Framework\Exception\ConfigurationMismatchException;
10+
use Magento\Framework\ObjectManagerInterface;
11+
12+
/**
13+
* Creates different implementations of config:set processors of type ConfigSetProcessorInterface.
14+
*
15+
* @see ConfigSetProcessorInterface
16+
* @see ConfigSetCommand
17+
*/
18+
class ConfigSetProcessorFactory
19+
{
20+
/**#@+
21+
* Constants for processors.
22+
*
23+
* default - save configuration
24+
* lock - save and lock configuration
25+
*/
26+
const TYPE_DEFAULT = 'default';
27+
const TYPE_LOCK = 'lock';
28+
/**#@-*/
29+
30+
/**
31+
* @var ObjectManagerInterface
32+
*/
33+
private $objectManager;
34+
35+
/**
36+
* List of class names that implement config:set processors
37+
*
38+
* @var array
39+
* @see ConfigSetProcessorInterface
40+
*/
41+
private $processors;
42+
43+
/**
44+
* @param ObjectManagerInterface $objectManager
45+
* @param array $processors
46+
*/
47+
public function __construct(
48+
ObjectManagerInterface $objectManager,
49+
array $processors = []
50+
) {
51+
$this->objectManager = $objectManager;
52+
$this->processors = $processors;
53+
}
54+
55+
/**
56+
* Creates an instance of specified processor.
57+
*
58+
* @param string $processorName The name of processor
59+
* @return ConfigSetProcessorInterface New processor instance
60+
* @throws ConfigurationMismatchException If processor type is not exists in processors array
61+
* or declared class has wrong implementation
62+
*/
63+
public function create($processorName)
64+
{
65+
if (!isset($this->processors[$processorName])) {
66+
throw new ConfigurationMismatchException(__('Class for type "%1" was not declared', $processorName));
67+
}
68+
69+
$object = $this->objectManager->create($this->processors[$processorName]);
70+
71+
if (!$object instanceof ConfigSetProcessorInterface) {
72+
throw new ConfigurationMismatchException(
73+
__('%1 should implement %2', get_class($object), ConfigSetProcessorInterface::class)
74+
);
75+
}
76+
77+
return $object;
78+
}
79+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
/**
3+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Config\Console\Command\ConfigSet;
7+
8+
use Magento\Config\Console\Command\ConfigSetCommand;
9+
use Magento\Framework\Exception\CouldNotSaveException;
10+
11+
/**
12+
* Allows to process different flows of config:set command.
13+
*
14+
* @see ConfigSetCommand
15+
*/
16+
interface ConfigSetProcessorInterface
17+
{
18+
/**
19+
* Processes config:set command.
20+
*
21+
* @param string $path The configuration path in format group/section/field_name
22+
* @param string $value The configuration value
23+
* @param string $scope The configuration scope (default, website, or store)
24+
* @param string $scopeCode The scope code
25+
* @return void
26+
* @throws CouldNotSaveException An exception on processing error
27+
*/
28+
public function process($path, $value, $scope, $scopeCode);
29+
}
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
<?php
2+
/**
3+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Config\Console\Command\ConfigSet;
7+
8+
use Magento\Config\App\Config\Type\System;
9+
use Magento\Config\Console\Command\ConfigSetCommand;
10+
use Magento\Config\Model\Config;
11+
use Magento\Config\Model\ConfigFactory;
12+
use Magento\Framework\App\Config\ConfigPathResolver;
13+
use Magento\Framework\App\DeploymentConfig;
14+
use Magento\Framework\Exception\CouldNotSaveException;
15+
use Magento\Store\Model\ScopeInterface;
16+
17+
/**
18+
* Processes default flow of config:set command.
19+
* This processor saves the value of configuration into database.
20+
*
21+
* {@inheritdoc}
22+
*/
23+
class DefaultProcessor implements ConfigSetProcessorInterface
24+
{
25+
/**
26+
* The factory that creates config model instances.
27+
*
28+
* @see Config
29+
* @var ConfigFactory
30+
*/
31+
private $configFactory;
32+
33+
/**
34+
* The deployment configuration reader.
35+
*
36+
* @var DeploymentConfig
37+
*/
38+
private $deploymentConfig;
39+
40+
/**
41+
* The resolver for configuration paths according to source type.
42+
*
43+
* @var ConfigPathResolver
44+
*/
45+
private $configPathResolver;
46+
47+
/**
48+
* @param ConfigFactory $configFactory The factory that creates config model instances
49+
* @param DeploymentConfig $deploymentConfig The deployment configuration reader
50+
* @param ConfigPathResolver $configPathResolver The resolver for configuration paths according to source type
51+
*/
52+
public function __construct(
53+
ConfigFactory $configFactory,
54+
DeploymentConfig $deploymentConfig,
55+
ConfigPathResolver $configPathResolver
56+
) {
57+
$this->configFactory = $configFactory;
58+
$this->deploymentConfig = $deploymentConfig;
59+
$this->configPathResolver = $configPathResolver;
60+
}
61+
62+
/**
63+
* Processes database flow of config:set command.
64+
* Requires installed application.
65+
*
66+
* {@inheritdoc}
67+
*/
68+
public function process($path, $value, $scope, $scopeCode)
69+
{
70+
if (!$this->deploymentConfig->isAvailable()) {
71+
throw new CouldNotSaveException(
72+
__(
73+
'We can\'t save this option because Magento is not installed. '
74+
. 'To lock this value, enter the command again using the --%1 option.',
75+
ConfigSetCommand::OPTION_LOCK
76+
)
77+
);
78+
}
79+
80+
if ($this->isLocked($path, $scope, $scopeCode)) {
81+
throw new CouldNotSaveException(
82+
__(
83+
'The value you set has already been locked. To change the value, use the --%1 option.',
84+
ConfigSetCommand::OPTION_LOCK
85+
)
86+
);
87+
}
88+
89+
try {
90+
/** @var Config $config */
91+
$config = $this->configFactory->create();
92+
$config->setDataByPath($path, $value);
93+
94+
if (in_array($scope, [ScopeInterface::SCOPE_WEBSITE, ScopeInterface::SCOPE_WEBSITES])) {
95+
$config->setWebsite($scopeCode);
96+
} elseif (in_array($scope, [ScopeInterface::SCOPE_STORE, ScopeInterface::SCOPE_STORES])) {
97+
$config->setStore($scopeCode);
98+
}
99+
100+
$config->save();
101+
} catch (\Exception $exception) {
102+
throw new CouldNotSaveException(__('%1', $exception->getMessage()), $exception);
103+
}
104+
}
105+
106+
/**
107+
* Checks whether configuration is locked in file storage.
108+
*
109+
* @param string $path The path to configuration
110+
* @param string $scope The scope of configuration
111+
* @param string $scopeCode The scope code of configuration
112+
* @return bool
113+
*/
114+
private function isLocked($path, $scope, $scopeCode)
115+
{
116+
$scopePath = $this->configPathResolver->resolve($path, $scope, $scopeCode, System::CONFIG_TYPE);
117+
118+
return $this->deploymentConfig->get($scopePath) !== null;
119+
}
120+
}

0 commit comments

Comments
 (0)