Skip to content

Commit 0e2fc30

Browse files
committed
Merge remote-tracking branch 'tango/MC-18348' into PR_2019_08_20
2 parents b68b98a + ac4cf19 commit 0e2fc30

File tree

3 files changed

+66
-9
lines changed

3 files changed

+66
-9
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
/**
3+
* Plugin for \Magento\Catalog\Model\Category\DataProvider
4+
*
5+
* Copyright © Magento, Inc. All rights reserved.
6+
* See COPYING.txt for license details.
7+
*/
8+
9+
declare(strict_types=1);
10+
11+
namespace Magento\Catalog\Model\Plugin;
12+
13+
use Magento\Catalog\Model\Category\DataProvider;
14+
use Magento\Framework\Exception\NoSuchEntityException;
15+
16+
/**
17+
* Sets the default value for Category Design Layout if provided
18+
*/
19+
class SetPageLayoutDefaultValue
20+
{
21+
private $defaultValue;
22+
23+
/**
24+
* @param string $defaultValue
25+
*/
26+
public function __construct(string $defaultValue = "")
27+
{
28+
$this->defaultValue = $defaultValue;
29+
}
30+
31+
/**
32+
* Sets the default value for Category Design Layout in data provider if provided
33+
*
34+
* @param DataProvider $subject
35+
* @param array $result
36+
* @return array
37+
*
38+
* @throws NoSuchEntityException
39+
*/
40+
public function afterGetDefaultMetaData(DataProvider $subject, array $result): array
41+
{
42+
$currentCategory = $subject->getCurrentCategory();
43+
44+
if ($currentCategory && !$currentCategory->getId() && array_key_exists('page_layout', $result)) {
45+
$result['page_layout']['default'] = $this->defaultValue ?: null;
46+
}
47+
48+
return $result;
49+
}
50+
}

app/code/Magento/Catalog/etc/di.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@
7676
<type name="Magento\Customer\Model\ResourceModel\Visitor">
7777
<plugin name="catalogLog" type="Magento\Catalog\Model\Plugin\Log" />
7878
</type>
79+
<type name="Magento\Catalog\Model\Category\DataProvider">
80+
<plugin name="set_page_layout_default_value" type="Magento\Catalog\Model\Plugin\SetPageLayoutDefaultValue" />
81+
</type>
7982
<type name="Magento\Theme\Block\Html\Topmenu">
8083
<plugin name="catalogTopmenu" type="Magento\Catalog\Plugin\Block\Topmenu" />
8184
</type>

app/code/Magento/Ui/Component/Form/Field/DefaultValue.php

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@
77

88
namespace Magento\Ui\Component\Form\Field;
99

10-
use Magento\Framework\View\Element\UiComponentFactory;
11-
use Magento\Framework\View\Element\UiComponent\ContextInterface;
1210
use Magento\Framework\App\Config\ScopeConfigInterface;
11+
use Magento\Framework\View\Element\UiComponent\ContextInterface;
12+
use Magento\Framework\View\Element\UiComponentFactory;
1313

14-
/** Field class has dynamic default value based on System Configuration path */
14+
/**
15+
* Field class has dynamic default value based on System Configuration path
16+
*/
1517
class DefaultValue extends \Magento\Ui\Component\Form\Field
1618
{
1719
/**
@@ -55,16 +57,18 @@ public function __construct(
5557
}
5658

5759
/**
58-
* {@inheritdoc}
60+
* @inheritdoc
5961
*/
6062
public function prepare()
6163
{
6264
parent::prepare();
6365
$store = $this->storeManager->getStore();
64-
$this->_data['config']['default'] = $this->scopeConfig->getValue(
65-
$this->path,
66-
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
67-
$store
68-
);
66+
if (empty($this->_data['config']['default'])) {
67+
$this->_data['config']['default'] = $this->scopeConfig->getValue(
68+
$this->path,
69+
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
70+
$store
71+
);
72+
}
6973
}
7074
}

0 commit comments

Comments
 (0)