Skip to content

Commit d05d425

Browse files
committed
MAGETWO-48240: Forms on new UI component do not support Single-Store Mode
1 parent 38dd0ed commit d05d425

File tree

7 files changed

+139
-28
lines changed

7 files changed

+139
-28
lines changed

app/code/Magento/Catalog/Ui/Component/Listing/Columns/Websites.php

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -41,37 +41,15 @@ public function __construct(
4141
$this->storeManager = $storeManager;
4242
}
4343

44-
/**
45-
* {@inheritdoc}
46-
*/
47-
public function prepareDataSource(array $dataSource)
48-
{
49-
$websiteNames = [];
50-
foreach ($this->getData('options') as $website) {
51-
$websiteNames[$website->getWebsiteId()] = $website->getName();
52-
}
53-
if (isset($dataSource['data']['items'])) {
54-
$fieldName = $this->getData('name');
55-
foreach ($dataSource['data']['items'] as & $item) {
56-
$websites = [];
57-
foreach ($item[$fieldName] as $websiteId) {
58-
$websites[] = $websiteNames[$websiteId];
59-
}
60-
$item[$fieldName] = implode(', ', $websites);
61-
}
62-
}
63-
64-
return $dataSource;
65-
}
66-
6744
/**
6845
* Prepare component configuration
6946
* @return void
7047
*/
7148
public function prepare()
7249
{
73-
if (!$this->storeManager->isSingleStoreMode()) {
74-
parent::prepare();
50+
parent::prepare();
51+
if ($this->storeManager->isSingleStoreMode()) {
52+
$this->_data['config']['componentDisabled'] = true;
7553
}
7654
}
7755
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@
230230
</item>
231231
</argument>
232232
</column>
233-
<column name="websites">
233+
<column name="websites" class="Magento\Catalog\Ui\Component\Listing\Columns\Websites">
234234
<argument name="data" xsi:type="array">
235235
<item name="options" xsi:type="object">Magento\Store\Model\ResourceModel\Website\Collection</item>
236236
<item name="config" xsi:type="array">

app/code/Magento/Cms/view/adminhtml/ui_component/cms_page_form.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@
169169
</argument>
170170
</field>
171171
</fieldset>
172-
<fieldset name="websites">
172+
<fieldset name="websites" class="Magento\Store\Ui\Component\Form\Fieldset\Websites">
173173
<argument name="data" xsi:type="array">
174174
<item name="config" xsi:type="array">
175175
<item name="collapsible" xsi:type="boolean">true</item>
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Customer\Ui\Component\Listing\Column;
7+
8+
use Magento\Framework\View\Element\UiComponent\ContextInterface;
9+
use Magento\Framework\View\Element\UiComponentFactory;
10+
use Magento\Ui\Component\Listing\Columns\Column;
11+
use Magento\Store\Model\StoreManagerInterface as StoreManager;
12+
13+
/**
14+
* Class Websites
15+
*/
16+
class Websites extends Column
17+
{
18+
/**
19+
* Store manager
20+
*
21+
* @var StoreManager
22+
*/
23+
protected $storeManager;
24+
25+
/**
26+
* @param ContextInterface $context
27+
* @param UiComponentFactory $uiComponentFactory
28+
* @param StoreManager $storeManager
29+
* @param array $components
30+
* @param array $data
31+
*/
32+
public function __construct(
33+
ContextInterface $context,
34+
UiComponentFactory $uiComponentFactory,
35+
StoreManager $storeManager,
36+
array $components = [],
37+
array $data = []
38+
) {
39+
$this->storeManager = $storeManager;
40+
parent::__construct($context, $uiComponentFactory, $components, $data);
41+
}
42+
43+
/**
44+
* Prepare component configuration
45+
* @return void
46+
*/
47+
public function prepare()
48+
{
49+
parent::prepare();
50+
if ($this->storeManager->isSingleStoreMode()) {
51+
$this->_data['config']['componentDisabled'] = true;
52+
}
53+
}
54+
}

app/code/Magento/Customer/view/adminhtml/ui_component/customer_listing.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@
245245
</item>
246246
</argument>
247247
</column>
248-
<column name="website_id">
248+
<column name="website_id" class="Magento\Customer\Ui\Component\Listing\Column\Websites">
249249
<argument name="data" xsi:type="array">
250250
<item name="config" xsi:type="array">
251251
<item name="filter" xsi:type="string">select</item>
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Store\Ui\Component\Form\Fieldset;
7+
8+
use Magento\Framework\View\Element\UiComponentInterface;
9+
use Magento\Framework\View\Element\UiComponent\ContextInterface;
10+
use Magento\Ui\Component\Form\Fieldset;
11+
use Magento\Store\Model\StoreManagerInterface as StoreManager;
12+
13+
/**
14+
* Class Websites Fieldset
15+
*/
16+
class Websites extends Fieldset
17+
{
18+
/**
19+
* Store manager
20+
*
21+
* @var StoreManager
22+
*/
23+
protected $storeManager;
24+
25+
/**
26+
* Constructor
27+
*
28+
* @param ContextInterface $context
29+
* @param StoreManager $storeManager
30+
* @param UiComponentInterface[] $components
31+
* @param array $data
32+
*/
33+
public function __construct(
34+
ContextInterface $context,
35+
StoreManager $storeManager,
36+
array $components = [],
37+
array $data = []
38+
) {
39+
parent::__construct($context, $components, $data);
40+
$this->storeManager = $storeManager;
41+
42+
}
43+
44+
/**
45+
* Prepare component configuration
46+
*
47+
* @return void
48+
*/
49+
public function prepare()
50+
{
51+
parent::prepare();
52+
if ($this->storeManager->isSingleStoreMode()) {
53+
$this->_data['config']['componentDisabled'] = true;
54+
}
55+
}
56+
}

app/code/Magento/Store/Ui/Component/Listing/Column/Store.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Magento\Framework\View\Element\UiComponentFactory;
1111
use Magento\Store\Model\System\Store as SystemStore;
1212
use Magento\Ui\Component\Listing\Columns\Column;
13+
use Magento\Store\Model\StoreManagerInterface as StoreManager;
1314

1415
/**
1516
* Class Store
@@ -30,6 +31,13 @@ class Store extends Column
3031
*/
3132
protected $systemStore;
3233

34+
/**
35+
* Store manager
36+
*
37+
* @var StoreManager
38+
*/
39+
protected $storeManager;
40+
3341
/**
3442
* @var string
3543
*/
@@ -40,6 +48,7 @@ class Store extends Column
4048
* @param UiComponentFactory $uiComponentFactory
4149
* @param SystemStore $systemStore
4250
* @param Escaper $escaper
51+
* @param StoreManager $storeManager
4352
* @param array $components
4453
* @param array $data
4554
* @param string $storeKey
@@ -49,13 +58,15 @@ public function __construct(
4958
UiComponentFactory $uiComponentFactory,
5059
SystemStore $systemStore,
5160
Escaper $escaper,
61+
StoreManager $storeManager,
5262
array $components = [],
5363
array $data = [],
5464
$storeKey = 'store_id'
5565
) {
5666
$this->systemStore = $systemStore;
5767
$this->escaper = $escaper;
5868
$this->storeKey = $storeKey;
69+
$this->storeManager = $storeManager;
5970
parent::__construct($context, $uiComponentFactory, $components, $data);
6071
}
6172

@@ -111,4 +122,16 @@ protected function prepareItem(array $item)
111122

112123
return $content;
113124
}
125+
126+
/**
127+
* Prepare component configuration
128+
* @return void
129+
*/
130+
public function prepare()
131+
{
132+
parent::prepare();
133+
if ($this->storeManager->isSingleStoreMode()) {
134+
$this->_data['config']['componentDisabled'] = true;
135+
}
136+
}
114137
}

0 commit comments

Comments
 (0)