Skip to content

Commit 91beff6

Browse files
committed
Merge remote-tracking branch 'falcon/MAGETWO-48516' into MAGETWO-60931
2 parents f547c35 + dd78e93 commit 91beff6

File tree

6 files changed

+189
-47
lines changed

6 files changed

+189
-47
lines changed

app/code/Magento/Catalog/Model/Category/DataProvider.php

Lines changed: 129 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,16 @@
55
*/
66
namespace Magento\Catalog\Model\Category;
77

8+
use Magento\Catalog\Api\Data\CategoryInterface;
9+
use Magento\Catalog\Api\Data\EavAttributeInterface;
10+
use Magento\Catalog\Model\Attribute\ScopeOverriddenValue;
811
use Magento\Catalog\Model\Category;
912
use Magento\Catalog\Model\ResourceModel\Eav\Attribute as EavAttribute;
1013
use Magento\Eav\Api\Data\AttributeInterface;
1114
use Magento\Eav\Model\Config;
1215
use Magento\Eav\Model\Entity\Type;
1316
use Magento\Catalog\Model\ResourceModel\Category\CollectionFactory as CategoryCollectionFactory;
17+
use Magento\Framework\Stdlib\ArrayManager;
1418
use Magento\Store\Model\Store;
1519
use Magento\Store\Model\StoreManagerInterface;
1620
use Magento\Ui\Component\Form\Field;
@@ -112,6 +116,16 @@ class DataProvider extends \Magento\Ui\DataProvider\AbstractDataProvider
112116
*/
113117
private $categoryFactory;
114118

119+
/**
120+
* @var ScopeOverriddenValue
121+
*/
122+
private $scopeOverriddenValue;
123+
124+
/**
125+
* @var ArrayManager
126+
*/
127+
private $arrayManager;
128+
115129
/**
116130
* DataProvider constructor
117131
*
@@ -151,8 +165,87 @@ public function __construct(
151165
$this->storeManager = $storeManager;
152166
$this->request = $request;
153167
$this->categoryFactory = $categoryFactory;
168+
154169
parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data);
155-
$this->meta = $this->prepareMeta($this->meta);
170+
}
171+
172+
/**
173+
* @inheritdoc
174+
*/
175+
public function getMeta()
176+
{
177+
$meta = parent::getMeta();
178+
$meta = $this->prepareMeta($meta);
179+
$meta = $this->addUseDefaultValueCheckbox($this->getCurrentCategory(), $meta);
180+
$meta = $this->resolveParentInheritance($this->getCurrentCategory(), $meta);
181+
182+
return $meta;
183+
}
184+
185+
/**
186+
* @param Category $category
187+
* @param array $meta
188+
* @return array
189+
*/
190+
private function addUseDefaultValueCheckbox(Category $category, array $meta)
191+
{
192+
/** @var EavAttributeInterface $attribute */
193+
foreach ($category->getAttributes() as $attribute) {
194+
$attributeCode = $attribute->getAttributeCode();
195+
$canDisplayUseDefault = $attribute->getScope() != EavAttributeInterface::SCOPE_GLOBAL_TEXT
196+
&& $category->getId()
197+
&& $category->getStoreId();
198+
$attributePath = $this->getArrayManager()->findPath($attributeCode, $meta);
199+
200+
if (
201+
!$attributePath
202+
|| !$canDisplayUseDefault
203+
|| in_array($attributeCode, $this->elementsWithUseConfigSetting
204+
)
205+
) {
206+
continue;
207+
}
208+
209+
$meta = $this->getArrayManager()->merge(
210+
[$attributePath, 'arguments/data/config'],
211+
$meta,
212+
[
213+
'service' => [
214+
'template' => 'ui/form/element/helper/service',
215+
],
216+
'disabled' => !$this->getScopeOverriddenValue()->containsValue(
217+
CategoryInterface::class,
218+
$category,
219+
$attributeCode,
220+
$this->request->getParam($this->requestScopeFieldName, Store::DEFAULT_STORE_ID)
221+
)
222+
]
223+
);
224+
}
225+
226+
return $meta;
227+
}
228+
229+
/**
230+
* Removes not necessary inheritance fields
231+
*
232+
* @param Category $category
233+
* @param array $meta
234+
* @return array
235+
*/
236+
private function resolveParentInheritance(Category $category, array $meta)
237+
{
238+
if (!$category->getParentId() || !$this->getArrayManager()->findPath('custom_use_parent_settings', $meta)) {
239+
return $meta;
240+
}
241+
242+
$meta = $this->getArrayManager()->merge(
243+
[$this->getArrayManager()->findPath('custom_use_parent_settings', $meta), 'arguments/data/config'],
244+
$meta,
245+
['visible' => false]
246+
);
247+
248+
return $meta;
156249
}
157250

158251
/**
@@ -204,7 +297,6 @@ public function getData()
204297
$category = $this->getCurrentCategory();
205298
if ($category) {
206299
$categoryData = $category->getData();
207-
$categoryData = $this->addUseDefaultSettings($category, $categoryData);
208300
$categoryData = $this->addUseConfigSettings($categoryData);
209301
$categoryData = $this->filterFields($categoryData);
210302
$categoryData = $this->convertValues($category, $categoryData);
@@ -292,6 +384,7 @@ protected function addUseConfigSettings($categoryData)
292384
* @param \Magento\Catalog\Model\Category $category
293385
* @param array $categoryData
294386
* @return array
387+
* @deprecated
295388
*/
296389
protected function addUseDefaultSettings($category, $categoryData)
297390
{
@@ -406,15 +499,6 @@ public function getDefaultMetaData($result)
406499
$result['use_config.available_sort_by']['default'] = true;
407500
$result['use_config.default_sort_by']['default'] = true;
408501
$result['use_config.filter_price_range']['default'] = true;
409-
if ($this->request->getParam('store') && $this->request->getParam('id')) {
410-
$result['use_default.url_key']['checked'] = true;
411-
$result['use_default.url_key']['default'] = true;
412-
$result['use_default.url_key']['visible'] = true;
413-
} else {
414-
$result['use_default.url_key']['checked'] = false;
415-
$result['use_default.url_key']['default'] = false;
416-
$result['use_default.url_key']['visible'] = false;
417-
}
418502

419503
return $result;
420504
}
@@ -454,7 +538,6 @@ protected function getFieldsMap()
454538
[
455539
'url_key',
456540
'url_key_create_redirect',
457-
'use_default.url_key',
458541
'url_key_group',
459542
'meta_title',
460543
'meta_keywords',
@@ -484,4 +567,38 @@ protected function getFieldsMap()
484567
],
485568
];
486569
}
570+
571+
/**
572+
* Retrieve scope overridden value
573+
*
574+
* @return ScopeOverriddenValue
575+
* @deprecated
576+
*/
577+
private function getScopeOverriddenValue()
578+
{
579+
if (null === $this->scopeOverriddenValue) {
580+
$this->scopeOverriddenValue = \Magento\Framework\App\ObjectManager::getInstance()->get(
581+
ScopeOverriddenValue::class
582+
);
583+
}
584+
585+
return $this->scopeOverriddenValue;
586+
}
587+
588+
/**
589+
* Retrieve array manager
590+
*
591+
* @return ArrayManager
592+
* @deprecated
593+
*/
594+
private function getArrayManager()
595+
{
596+
if (null === $this->arrayManager) {
597+
$this->arrayManager = \Magento\Framework\App\ObjectManager::getInstance()->get(
598+
ArrayManager::class
599+
);
600+
}
601+
602+
return $this->arrayManager;
603+
}
487604
}

app/code/Magento/Catalog/view/adminhtml/ui_component/category_form.xml

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -375,19 +375,6 @@
375375
<item name="source" xsi:type="string">category</item>
376376
<item name="label" xsi:type="string" translate="true">URL Key</item>
377377
<item name="sortOrder" xsi:type="number">10</item>
378-
<item name="imports" xsi:type="array">
379-
<item name="disabled" xsi:type="string">${ $.provider }:data.use_default.url_key</item>
380-
</item>
381-
</item>
382-
</argument>
383-
</field>
384-
<field name="use_default.url_key">
385-
<argument name="data" xsi:type="array">
386-
<item name="config" xsi:type="array">
387-
<item name="description" xsi:type="string" translate="true">Use Default</item>
388-
<item name="dataType" xsi:type="string">boolean</item>
389-
<item name="formElement" xsi:type="string">checkbox</item>
390-
<item name="sortOrder" xsi:type="number">20</item>
391378
</item>
392379
</argument>
393380
</field>
@@ -453,17 +440,18 @@
453440
<field name="custom_use_parent_settings">
454441
<argument name="data" xsi:type="array">
455442
<item name="config" xsi:type="array">
456-
<item name="additionalClasses" xsi:type="string">admin__field-no-label</item>
443+
<item name="additionalClasses" xsi:type="string">admin__field-x-small</item>
457444
<item name="sortOrder" xsi:type="number">170</item>
458-
<item name="label" xsi:type="string"/>
459-
<item name="description" xsi:type="string" translate="true">Use Parent Category Settings</item>
445+
<item name="label" xsi:type="string">Use Parent Category Settings</item>
460446
<item name="dataType" xsi:type="string">boolean</item>
461447
<item name="formElement" xsi:type="string">checkbox</item>
462448
<item name="valueMap" xsi:type="array">
463449
<item name="true" xsi:type="string">1</item>
464450
<item name="false" xsi:type="string">0</item>
465451
</item>
466452
<item name="default" xsi:type="string">0</item>
453+
<item name="component" xsi:type="string">Magento_Ui/js/form/element/single-checkbox</item>
454+
<item name="prefer" xsi:type="string">toggle</item>
467455
</item>
468456
</argument>
469457
</field>
@@ -509,20 +497,21 @@
509497
<field name="custom_apply_to_products">
510498
<argument name="data" xsi:type="array">
511499
<item name="config" xsi:type="array">
512-
<item name="additionalClasses" xsi:type="string">admin__field-no-label</item>
500+
<item name="additionalClasses" xsi:type="string">admin__field-x-small</item>
513501
<item name="sortOrder" xsi:type="number">210</item>
514-
<item name="label" xsi:type="string"/>
515-
<item name="description" xsi:type="string" translate="true">Apply Design to Products</item>
502+
<item name="label" xsi:type="string" translate="true">Apply Design to Products</item>
516503
<item name="dataType" xsi:type="string">boolean</item>
517504
<item name="formElement" xsi:type="string">checkbox</item>
518-
<item name="imports" xsi:type="array">
519-
<item name="disabled" xsi:type="string">ns = ${ $.ns }, index = custom_use_parent_settings :checked</item>
520-
</item>
521505
<item name="valueMap" xsi:type="array">
522506
<item name="true" xsi:type="string">1</item>
523507
<item name="false" xsi:type="string">0</item>
524508
</item>
525509
<item name="default" xsi:type="string">0</item>
510+
<item name="component" xsi:type="string">Magento_Ui/js/form/element/single-checkbox</item>
511+
<item name="prefer" xsi:type="string">toggle</item>
512+
<item name="imports" xsi:type="array">
513+
<item name="disabled" xsi:type="string">ns = ${ $.ns }, index = custom_use_parent_settings:checked</item>
514+
</item>
526515
</item>
527516
</argument>
528517
</field>

app/code/Magento/Ui/view/base/web/js/form/element/file-uploader.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ define([
7272

7373
this.value(value);
7474
this.on('value', this.onUpdate.bind(this));
75+
this.isUseDefault(this.disabled());
7576

7677
return this;
7778
},

app/code/Magento/Ui/view/base/web/templates/form/element/uploader/uploader.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,6 @@
2929

3030
<each args="data: value, as: '$file'" render="$parent.getPreviewTmpl($file)"/>
3131
</div>
32+
<render args="$data.service.template" if="$data.hasService()"/>
3233
</div>
33-
</div>
34+
</div>

lib/internal/Magento/Framework/Stdlib/ArrayManager.php

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class ArrayManager
3030
/**
3131
* Check if node exists
3232
*
33-
* @param string $path
33+
* @param array|string $path
3434
* @param array $data
3535
* @param string $delimiter
3636
* @return bool
@@ -43,7 +43,7 @@ public function exists($path, array $data, $delimiter = self::DEFAULT_PATH_DELIM
4343
/**
4444
* Retrieve node
4545
*
46-
* @param string $path
46+
* @param array|string $path
4747
* @param array $data
4848
* @param null $defaultValue
4949
* @param string $delimiter
@@ -57,7 +57,7 @@ public function get($path, array $data, $defaultValue = null, $delimiter = self:
5757
/**
5858
* Set value into node and return modified data
5959
*
60-
* @param string $path
60+
* @param array|string $path
6161
* @param array $data
6262
* @param mixed $value
6363
* @param string $delimiter
@@ -75,7 +75,7 @@ public function set($path, array $data, $value, $delimiter = self::DEFAULT_PATH_
7575
/**
7676
* Set value into existing node and return modified data
7777
*
78-
* @param string $path
78+
* @param array|string $path
7979
* @param array $data
8080
* @param mixed $value
8181
* @param string $delimiter
@@ -93,7 +93,7 @@ public function replace($path, array $data, $value, $delimiter = self::DEFAULT_P
9393
/**
9494
* Move value from one location to another
9595
*
96-
* @param string $path
96+
* @param array|string $path
9797
* @param string $targetPath
9898
* @param array $data
9999
* @param bool $overwrite
@@ -120,7 +120,7 @@ public function move($path, $targetPath, array $data, $overwrite = false, $delim
120120
/**
121121
* Merge value with node and return modified data
122122
*
123-
* @param string $path
123+
* @param array|string $path
124124
* @param array $data
125125
* @param array $value
126126
* @param string $delimiter
@@ -141,7 +141,7 @@ public function merge($path, array $data, array $value, $delimiter = self::DEFAU
141141
/**
142142
* Populate nested array if possible and needed
143143
*
144-
* @param string $path
144+
* @param array|string $path
145145
* @param array $data
146146
* @param string $delimiter
147147
* @return array
@@ -156,7 +156,7 @@ public function populate($path, array $data, $delimiter = self::DEFAULT_PATH_DEL
156156
/**
157157
* Remove node and return modified data
158158
*
159-
* @param string $path
159+
* @param array|string $path
160160
* @param array $data
161161
* @param string $delimiter
162162
* @return array
@@ -173,14 +173,18 @@ public function remove($path, array $data, $delimiter = self::DEFAULT_PATH_DELIM
173173
/**
174174
* Finds node in nested array and saves its index and parent node reference
175175
*
176-
* @param string $path
176+
* @param array|string $path
177177
* @param array $data
178178
* @param string $delimiter
179179
* @param bool $populate
180180
* @return bool
181181
*/
182182
protected function find($path, array &$data, $delimiter, $populate = false)
183183
{
184+
if (is_array($path)) {
185+
$path = implode($delimiter, $path);
186+
}
187+
184188
if ($path === null) {
185189
return false;
186190
}

0 commit comments

Comments
 (0)