Skip to content

Commit 286b0e6

Browse files
author
Stanislav Idolov
authored
ENGCOM-1206: [Improvement] Implement design theme grid on ui component #14470
2 parents a753586 + 741967e commit 286b0e6

File tree

13 files changed

+385
-11
lines changed

13 files changed

+385
-11
lines changed

app/code/Magento/Theme/Controller/Adminhtml/System/Design/Theme/Index.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public function execute()
2121
{
2222
$this->_view->loadLayout();
2323
$this->_setActiveMenu('Magento_Theme::system_design_theme');
24+
$this->_view->getLayout()->getBlock('page.title')->setPageTitle('Themes');
2425
$this->_view->renderLayout();
2526
}
2627
}

app/code/Magento/Theme/Model/ResourceModel/Theme/Collection.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\Ab
1717
*/
1818
const DEFAULT_PAGE_SIZE = 6;
1919

20+
/**
21+
* @var string
22+
*/
23+
protected $_idFieldName = 'theme_id';
24+
2025
/**
2126
* Collection initialization
2227
*

app/code/Magento/Theme/Model/ResourceModel/Theme/Grid/Collection.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@
77

88
/**
99
* Theme grid collection
10+
* @deprecated
11+
* @see \Magento\Theme\Ui\Component\Theme\DataProvider\SearchResult
1012
*/
1113
class Collection extends \Magento\Theme\Model\ResourceModel\Theme\Collection
1214
{
1315
/**
1416
* Add area filter
1517
*
16-
* @return \Magento\Theme\Model\ResourceModel\Theme\Collection
18+
* @return $this
1719
*/
1820
protected function _initSelect()
1921
{

app/code/Magento/Theme/Test/Unit/Controller/Adminhtml/System/Design/Theme/IndexTest.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,18 @@ public function testIndexAction()
2828
->method('getMenuModel')
2929
->will($this->returnValue($menuModel));
3030

31+
$titleBlock = $this->createMock(\Magento\Theme\Block\Html\Title::class);
32+
$titleBlock->expects($this->once())->method('setPageTitle');
33+
3134
$layout = $this->createMock(\Magento\Framework\View\LayoutInterface::class);
3235
$layout->expects($this->any())
3336
->method('getBlock')
34-
->with($this->equalTo('menu'))
35-
->will($this->returnValue($menuBlock));
37+
->willReturnMap([
38+
['menu', $menuBlock],
39+
['page.title', $titleBlock]
40+
]);
3641

37-
$this->view->expects($this->once())
42+
$this->view->expects($this->any())
3843
->method('getLayout')
3944
->will($this->returnValue($layout));
4045

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Magento\Theme\Test\Unit\Ui\Component\Listing\Column;
10+
11+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
12+
use Magento\Framework\UrlInterface;
13+
use Magento\Theme\Ui\Component\Listing\Column\ViewAction;
14+
15+
/**
16+
* Class ViewActionTest contains unit tests for \Magento\Theme\Ui\Component\Listing\Column\ViewAction class
17+
*
18+
* @SuppressWarnings(PHPMD.LongVariable)
19+
*/
20+
class ViewActionTest extends \PHPUnit\Framework\TestCase
21+
{
22+
/**
23+
* @var ViewAction
24+
*/
25+
protected $model;
26+
27+
/**
28+
* @var UrlInterface|\PHPUnit_Framework_MockObject_MockObject
29+
*/
30+
protected $urlBuilder;
31+
32+
/**
33+
* @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager
34+
*/
35+
protected $objectManager;
36+
37+
/**
38+
* SetUp method
39+
*
40+
* @return void
41+
*/
42+
protected function setUp()
43+
{
44+
$this->objectManager = new ObjectManager($this);
45+
$this->urlBuilder = $this->getMockForAbstractClass(\Magento\Framework\UrlInterface::class);
46+
}
47+
48+
/**
49+
* @param array $data
50+
* @param array $dataSourceItems
51+
* @param array $expectedDataSourceItems
52+
* @param string $expectedUrlPath
53+
* @param array $expectedUrlParam
54+
*
55+
* @dataProvider getPrepareDataSourceDataProvider
56+
* @return void
57+
*/
58+
public function testPrepareDataSource(
59+
$data,
60+
$dataSourceItems,
61+
$expectedDataSourceItems,
62+
$expectedUrlPath,
63+
$expectedUrlParam
64+
) {
65+
$contextMock = $this->getMockBuilder(\Magento\Framework\View\Element\UiComponent\ContextInterface::class)
66+
->getMockForAbstractClass();
67+
$processor = $this->getMockBuilder(\Magento\Framework\View\Element\UiComponent\Processor::class)
68+
->disableOriginalConstructor()
69+
->getMock();
70+
$contextMock->expects($this->never())->method('getProcessor')->willReturn($processor);
71+
$this->model = $this->objectManager->getObject(
72+
ViewAction::class,
73+
[
74+
'urlBuilder' => $this->urlBuilder,
75+
'data' => $data,
76+
'context' => $contextMock,
77+
]
78+
);
79+
80+
$this->urlBuilder->expects($this->once())
81+
->method('getUrl')
82+
->with($expectedUrlPath, $expectedUrlParam)
83+
->willReturn('url');
84+
85+
$dataSource = [
86+
'data' => [
87+
'items' => $dataSourceItems
88+
]
89+
];
90+
$dataSource = $this->model->prepareDataSource($dataSource);
91+
$this->assertEquals($expectedDataSourceItems, $dataSource['data']['items']);
92+
}
93+
94+
/**
95+
* Data provider for testPrepareDataSource
96+
* @return array
97+
*/
98+
public function getPrepareDataSourceDataProvider()
99+
{
100+
return [
101+
[
102+
['name' => 'itemName', 'config' => []],
103+
[['itemName' => '', 'entity_id' => 1]],
104+
[['itemName' => ['view' => ['href' => 'url', 'label' => __('View')]], 'entity_id' => 1]],
105+
'#',
106+
['id' => 1]
107+
],
108+
[
109+
['name' => 'itemName', 'config' => [
110+
'viewUrlPath' => 'url_path',
111+
'urlEntityParamName' => 'theme_id',
112+
'indexField' => 'theme_id']
113+
],
114+
[['itemName' => '', 'theme_id' => 2]],
115+
[['itemName' => ['view' => ['href' => 'url', 'label' => __('View')]], 'theme_id' => 2]],
116+
'url_path',
117+
['theme_id' => 2]
118+
]
119+
];
120+
}
121+
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Magento\Theme\Ui\Component\Listing\Column;
10+
11+
use Magento\Framework\UrlInterface;
12+
use Magento\Framework\View\Element\UiComponent\ContextInterface;
13+
use Magento\Framework\View\Element\UiComponentFactory;
14+
use Magento\Ui\Component\Listing\Columns\Column;
15+
16+
/**
17+
* Class ViewAction
18+
*/
19+
class ViewAction extends Column
20+
{
21+
/**
22+
* @var UrlInterface
23+
*/
24+
private $urlBuilder;
25+
26+
/**
27+
* Constructor
28+
*
29+
* @param ContextInterface $context
30+
* @param UiComponentFactory $uiComponentFactory
31+
* @param UrlInterface $urlBuilder
32+
* @param array $components
33+
* @param array $data
34+
*/
35+
public function __construct(
36+
ContextInterface $context,
37+
UiComponentFactory $uiComponentFactory,
38+
UrlInterface $urlBuilder,
39+
array $components = [],
40+
array $data = []
41+
) {
42+
$this->urlBuilder = $urlBuilder;
43+
parent::__construct($context, $uiComponentFactory, $components, $data);
44+
}
45+
46+
/**
47+
* Prepare Theme Data Source
48+
*
49+
* @param array $dataSource
50+
* @return array
51+
*/
52+
public function prepareDataSource(array $dataSource) : array
53+
{
54+
if (isset($dataSource['data']['items'])) {
55+
foreach ($dataSource['data']['items'] as & $item) {
56+
$indexField = $this->getData('config/indexField') ?: 'entity_id';
57+
if (isset($item[$indexField])) {
58+
$viewUrlPath = $this->getData('config/viewUrlPath') ?: '#';
59+
$urlEntityParamName = $this->getData('config/urlEntityParamName') ?: 'id';
60+
$item[$this->getData('name')] = [
61+
'view' => [
62+
'href' => $this->urlBuilder->getUrl(
63+
$viewUrlPath,
64+
[
65+
$urlEntityParamName => $item[$indexField]
66+
]
67+
),
68+
'label' => __('View')
69+
]
70+
];
71+
}
72+
}
73+
}
74+
75+
return $dataSource;
76+
}
77+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Magento\Theme\Ui\Component\Theme\DataProvider;
10+
11+
/**
12+
* Theme search result
13+
*/
14+
class SearchResult extends \Magento\Framework\View\Element\UiComponent\DataProvider\SearchResult
15+
{
16+
/**
17+
* {@inheritdoc}
18+
*/
19+
protected $_map = [
20+
'fields' => [
21+
'theme_id' => 'main_table.theme_id',
22+
'theme_title' => 'main_table.theme_title',
23+
'theme_path' => 'main_table.theme_path',
24+
'parent_theme_title' => 'parent.theme_title',
25+
],
26+
];
27+
28+
/**
29+
* Add area and type filters
30+
* Join parent theme title
31+
*
32+
* @return $this
33+
*/
34+
protected function _initSelect()
35+
{
36+
parent::_initSelect();
37+
$this
38+
->addFieldToFilter('main_table.area', \Magento\Framework\App\Area::AREA_FRONTEND)
39+
->addFieldToFilter('main_table.type', ['in' => [
40+
\Magento\Framework\View\Design\ThemeInterface::TYPE_PHYSICAL,
41+
\Magento\Framework\View\Design\ThemeInterface::TYPE_VIRTUAL,
42+
]])
43+
;
44+
45+
$this->getSelect()->joinLeft(
46+
['parent' => $this->getMainTable()],
47+
'main_table.parent_id = parent.theme_id',
48+
['parent_theme_title' => 'parent.theme_title']
49+
);
50+
51+
return $this;
52+
}
53+
}

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@
108108
<arguments>
109109
<argument name="collections" xsi:type="array">
110110
<item name="design_config_listing_data_source" xsi:type="string">Magento\Theme\Model\ResourceModel\Design\Config\Grid\Collection</item>
111+
<item name="design_theme_listing_data_source" xsi:type="string">Magento\Theme\Ui\Component\Theme\DataProvider\SearchResult</item>
111112
</argument>
112113
</arguments>
113114
</type>
@@ -273,4 +274,11 @@
273274
<argument name="themeList" xsi:type="object">Magento\Theme\Model\ResourceModel\Theme\Collection</argument>
274275
</arguments>
275276
</type>
277+
<type name="Magento\Theme\Ui\Component\Theme\DataProvider\SearchResult">
278+
<arguments>
279+
<argument name="mainTable" xsi:type="string">theme</argument>
280+
<argument name="resourceModel" xsi:type="string">Magento\Theme\Model\ResourceModel\Theme</argument>
281+
<argument name="identifierName" xsi:type="string">theme_id</argument>
282+
</arguments>
283+
</type>
276284
</config>

app/code/Magento/Theme/i18n/en_US.csv

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,3 +185,6 @@ Settings,Settings
185185
"2 columns with left bar","2 columns with left bar"
186186
"2 columns with right bar","2 columns with right bar"
187187
"3 columns","3 columns"
188+
ID,ID
189+
View,View
190+
Action,Action

app/code/Magento/Theme/view/adminhtml/layout/adminhtml_system_design_theme_index.xml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,9 @@
66
*/
77
-->
88
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
9-
<update handle="formkey"/>
10-
<update handle="adminhtml_system_design_theme_block"/>
119
<body>
1210
<referenceContainer name="content">
13-
<block class="Magento\Theme\Block\Adminhtml\System\Design\Theme" name="design_theme"/>
11+
<uiComponent name="design_theme_listing"/>
1412
</referenceContainer>
1513
</body>
1614
</page>

0 commit comments

Comments
 (0)