Skip to content

Commit f535fe1

Browse files
Merge branch 'MAGETWO-59376' of https://github.com/magento-falcons/magento2ce into MAGETWO-59376
2 parents f33dd60 + 69fe8b8 commit f535fe1

File tree

4 files changed

+267
-100
lines changed

4 files changed

+267
-100
lines changed

app/code/Magento/Theme/Model/Design/Config/DataProvider.php

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,13 @@
55
*/
66
namespace Magento\Theme\Model\Design\Config;
77

8+
use Magento\Framework\App\Config\ScopeCodeResolver;
9+
use Magento\Framework\App\ObjectManager;
810
use Magento\Theme\Model\ResourceModel\Design\Config\Collection;
911
use Magento\Theme\Model\ResourceModel\Design\Config\CollectionFactory;
1012
use Magento\Ui\DataProvider\AbstractDataProvider;
13+
use Magento\Config\Model\Config\Reader\Source\Deployed\SettingChecker;
14+
use Magento\Framework\App\RequestInterface;
1115

1216
class DataProvider extends AbstractDataProvider
1317
{
@@ -31,6 +35,21 @@ class DataProvider extends AbstractDataProvider
3135
*/
3236
private $metadataLoader;
3337

38+
/**
39+
* @var SettingChecker
40+
*/
41+
private $settingChecker;
42+
43+
/**
44+
* @var RequestInterface
45+
*/
46+
private $request;
47+
48+
/**
49+
* @var ScopeCodeResolver
50+
*/
51+
private $scopeCodeResolver;
52+
3453
/**
3554
* @param string $name
3655
* @param string $primaryFieldName
@@ -78,4 +97,84 @@ public function getData()
7897
$this->loadedData = $this->dataLoader->getData();
7998
return $this->loadedData;
8099
}
100+
101+
/**
102+
* {@inheritdoc}
103+
*/
104+
public function getMeta()
105+
{
106+
$meta = parent::getMeta();
107+
if (!isset($meta['other_settings']['children'])) {
108+
return $meta;
109+
}
110+
111+
$request = $this->getRequest()->getParams();
112+
if (!isset($request['scope'])) {
113+
return $meta;
114+
}
115+
116+
$scope = $request['scope'];
117+
$scopeCode = $this->getScopeCodeResolver()->resolve(
118+
$scope,
119+
isset($request['scope_id']) ? $request['scope_id'] : null
120+
);
121+
122+
foreach ($meta['other_settings']['children'] as $settingGroupName => &$settingGroup) {
123+
foreach ($settingGroup['children'] as $fieldName => &$field) {
124+
$path = sprintf(
125+
'design/%s/%s',
126+
$settingGroupName,
127+
preg_replace('/^' . $settingGroupName . '_/', '', $fieldName)
128+
);
129+
$isReadOnly = $this->getSettingChecker()->isReadOnly(
130+
$path,
131+
$scope,
132+
$scopeCode
133+
);
134+
135+
if ($isReadOnly) {
136+
$field['arguments']['data']['config']['disabled'] = true;
137+
$field['arguments']['data']['config']['is_disable_inheritance'] = true;
138+
}
139+
}
140+
}
141+
142+
return $meta;
143+
}
144+
145+
/**
146+
* @deprecated
147+
* @return ScopeCodeResolver
148+
*/
149+
private function getScopeCodeResolver()
150+
{
151+
if ($this->scopeCodeResolver === null) {
152+
$this->scopeCodeResolver = ObjectManager::getInstance()->get(ScopeCodeResolver::class);
153+
}
154+
return $this->scopeCodeResolver;
155+
}
156+
157+
/**
158+
* @deprecated
159+
* @return SettingChecker
160+
*/
161+
private function getSettingChecker()
162+
{
163+
if ($this->settingChecker === null) {
164+
$this->settingChecker = ObjectManager::getInstance()->get(SettingChecker::class);
165+
}
166+
return $this->settingChecker;
167+
}
168+
169+
/**
170+
* @deprecated
171+
* @return RequestInterface
172+
*/
173+
private function getRequest()
174+
{
175+
if ($this->request === null) {
176+
$this->request = ObjectManager::getInstance()->get(RequestInterface::class);
177+
}
178+
return $this->request;
179+
}
81180
}

app/code/Magento/Theme/Test/Unit/Model/Design/Config/DataProviderTest.php

Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
*/
66
namespace Magento\Theme\Test\Unit\Model\Design\Config;
77

8+
use Magento\Config\Model\Config\Reader\Source\Deployed\SettingChecker;
9+
use Magento\Framework\App\Config\ScopeCodeResolver;
10+
use Magento\Framework\App\RequestInterface;
11+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
812
use Magento\Theme\Model\Design\Config\DataLoader;
913
use Magento\Theme\Model\Design\Config\DataProvider;
1014
use Magento\Theme\Model\Design\Config\MetadataLoader;
@@ -32,8 +36,29 @@ class DataProviderTest extends \PHPUnit_Framework_TestCase
3236
*/
3337
protected $collection;
3438

39+
/**
40+
* @var ObjectManager
41+
*/
42+
private $objectManager;
43+
44+
/**
45+
* @var RequestInterface|\PHPUnit_Framework_MockObject_MockObject
46+
*/
47+
private $requestMock;
48+
49+
/**
50+
* @var ScopeCodeResolver|\PHPUnit_Framework_MockObject_MockObject
51+
*/
52+
private $scopeCodeResolverMock;
53+
54+
/**
55+
* @var SettingChecker|\PHPUnit_Framework_MockObject_MockObject
56+
*/
57+
private $settingCheckerMock;
58+
3559
protected function setUp()
3660
{
61+
$this->objectManager = new ObjectManager($this);
3762
$this->dataLoader = $this->getMockBuilder('Magento\Theme\Model\Design\Config\DataProvider\DataLoader')
3863
->disableOriginalConstructor()
3964
->getMock();
@@ -57,6 +82,16 @@ protected function setUp()
5782
->method('create')
5883
->willReturn($this->collection);
5984

85+
$this->requestMock = $this->getMockBuilder(RequestInterface::class)
86+
->disableOriginalConstructor()
87+
->getMock();
88+
$this->scopeCodeResolverMock = $this->getMockBuilder(ScopeCodeResolver::class)
89+
->disableOriginalConstructor()
90+
->getMock();
91+
$this->settingCheckerMock = $this->getMockBuilder(SettingChecker::class)
92+
->disableOriginalConstructor()
93+
->getMock();
94+
6095
$this->model = new DataProvider(
6196
'scope',
6297
'scope',
@@ -65,6 +100,21 @@ protected function setUp()
65100
$this->metadataLoader,
66101
$collectionFactory
67102
);
103+
$this->objectManager->setBackwardCompatibleProperty(
104+
$this->model,
105+
'request',
106+
$this->requestMock
107+
);
108+
$this->objectManager->setBackwardCompatibleProperty(
109+
$this->model,
110+
'scopeCodeResolver',
111+
$this->scopeCodeResolverMock
112+
);
113+
$this->objectManager->setBackwardCompatibleProperty(
114+
$this->model,
115+
'settingChecker',
116+
$this->settingCheckerMock
117+
);
68118
}
69119

70120
public function testGetData()
@@ -79,4 +129,119 @@ public function testGetData()
79129

80130
$this->assertEquals($data, $this->model->getData());
81131
}
132+
133+
/**
134+
* @param array $inputMeta
135+
* @param array $expectedMeta
136+
* @param array $request
137+
* @dataProvider getMetaDataProvider
138+
*/
139+
public function testGetMeta(array $inputMeta, array $expectedMeta, array $request)
140+
{
141+
$this->requestMock->expects($this->any())
142+
->method('getParams')
143+
->willReturn($request);
144+
$this->scopeCodeResolverMock->expects($this->any())
145+
->method('resolve')
146+
->with('stores', 1)
147+
->willReturn('default');
148+
$this->settingCheckerMock->expects($this->any())
149+
->method('isReadOnly')
150+
->withConsecutive(
151+
['design/head/welcome', 'stores', 'default'],
152+
['design/head/logo', 'stores', 'default'],
153+
['design/head/head', 'stores', 'default']
154+
)
155+
->willReturnOnConsecutiveCalls(
156+
true,
157+
false,
158+
true
159+
);
160+
161+
$this->objectManager->setBackwardCompatibleProperty(
162+
$this->model,
163+
'meta',
164+
$inputMeta
165+
);
166+
167+
$this->assertSame($expectedMeta, $this->model->getMeta());
168+
}
169+
170+
/**
171+
* @return array
172+
*/
173+
public function getMetaDataProvider()
174+
{
175+
return [
176+
[
177+
[
178+
'option1'
179+
],
180+
[
181+
'option1'
182+
],
183+
[
184+
'scope' => 'default'
185+
]
186+
],
187+
[
188+
[
189+
'other_settings' => [
190+
'children' => [
191+
'head' => [
192+
'children' => [
193+
'head_welcome' => [
194+
195+
],
196+
'head_logo' => [
197+
198+
],
199+
'head_head' => [
200+
201+
]
202+
]
203+
]
204+
]
205+
]
206+
],
207+
[
208+
'other_settings' => [
209+
'children' => [
210+
'head' => [
211+
'children' => [
212+
'head_welcome' => [
213+
'arguments' => [
214+
'data' => [
215+
'config' => [
216+
'disabled' => true,
217+
'is_disable_inheritance' => true,
218+
]
219+
]
220+
]
221+
],
222+
'head_logo' => [
223+
224+
],
225+
'head_head' => [
226+
'arguments' => [
227+
'data' => [
228+
'config' => [
229+
'disabled' => true,
230+
'is_disable_inheritance' => true,
231+
]
232+
]
233+
]
234+
]
235+
]
236+
]
237+
]
238+
]
239+
],
240+
[
241+
'scope' => 'stores',
242+
'scope_id' => 1
243+
]
244+
]
245+
];
246+
}
82247
}

lib/internal/Magento/Framework/ObjectManager/Config/Compiled.php

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -129,15 +129,9 @@ public function getPreference($type)
129129
*/
130130
public function extend(array $configuration)
131131
{
132-
$this->arguments = isset($configuration['arguments'])
133-
? array_replace($this->arguments, $configuration['arguments'])
134-
: $this->arguments;
135-
$this->virtualTypes = isset($configuration['instanceTypes'])
136-
? array_replace($this->virtualTypes, $configuration['instanceTypes'])
137-
: $this->virtualTypes;
138-
$this->preferences = isset($configuration['preferences'])
139-
? array_replace($this->preferences, $configuration['preferences'])
140-
: $this->preferences;
132+
$this->arguments = $configuration['arguments'];
133+
$this->virtualTypes = $configuration['instanceTypes'];
134+
$this->preferences = $configuration['preferences'];
141135
}
142136

143137
/**

0 commit comments

Comments
 (0)