Skip to content

Commit f391ced

Browse files
author
Maxim Medinskiy
committed
MAGETWO-5824: PHP - Hide/Show Column
1 parent 1822208 commit f391ced

File tree

8 files changed

+361
-4
lines changed

8 files changed

+361
-4
lines changed
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Cms\Controller\Adminhtml;
7+
8+
use Magento\Framework\Model\Resource\Db\Collection\AbstractCollection;
9+
10+
/**
11+
* Class AbstractMassStatus
12+
*/
13+
class AbstractMassStatus extends \Magento\Backend\App\Action
14+
{
15+
/**
16+
* Field id
17+
*/
18+
const ID_FIELD = 'entity_id';
19+
20+
/**
21+
* Redirect url
22+
*/
23+
const REDIRECT_URL = '*/*/';
24+
25+
/**
26+
* Resource collection
27+
*
28+
* @var string
29+
*/
30+
protected $collection = 'Magento\Framework\Model\Resource\Db\Collection\AbstractCollection';
31+
32+
/**
33+
* Model
34+
*
35+
* @var string
36+
*/
37+
protected $model = 'Magento\Framework\Model\AbstractModel';
38+
39+
40+
/**
41+
* Item status
42+
*
43+
* @var bool
44+
*/
45+
protected $status = true;
46+
/**
47+
* Execute action
48+
*
49+
* @return \Magento\Backend\Model\View\Result\Redirect
50+
* @throws \Magento\Framework\Exception\LocalizedException|\Exception
51+
*/
52+
public function execute()
53+
{
54+
$selected = $this->getRequest()->getParam('selected');
55+
$excluded = $this->getRequest()->getParam('excluded');
56+
57+
if (isset($excluded)) {
58+
if (!empty($excluded)) {
59+
$this->excludedSetStatus($excluded);
60+
} else {
61+
$this->setStatusAll();
62+
}
63+
} elseif (!empty($selected)) {
64+
$this->selectedSetStatus($selected);
65+
} else {
66+
$this->messageManager->addError(__('Please select item(s).'));
67+
}
68+
69+
return $this->getDefaultResult();
70+
}
71+
72+
/**
73+
* {@inheritdoc}
74+
*
75+
* @return \Magento\Backend\Model\View\Result\Redirect
76+
*/
77+
public function getDefaultResult()
78+
{
79+
$resultRedirect = $this->resultRedirectFactory->create();
80+
return $resultRedirect->setPath(static::REDIRECT_URL);
81+
}
82+
83+
/**
84+
* Set status to all
85+
*
86+
* @return void
87+
* @throws \Exception
88+
*/
89+
protected function setStatusAll()
90+
{
91+
/** @var AbstractCollection $collection */
92+
$collection = $this->_objectManager->get($this->collection);
93+
$this->setStatus($collection);
94+
}
95+
96+
/**
97+
* Set status to all but the not selected
98+
*
99+
* @param array $excluded
100+
* @return void
101+
* @throws \Exception
102+
*/
103+
protected function excludedSetStatus(array $excluded)
104+
{
105+
/** @var AbstractCollection $collection */
106+
$collection = $this->_objectManager->get($this->collection);
107+
$collection->addFieldToFilter(static::ID_FIELD, ['nin' => $excluded]);
108+
$this->setStatus($collection);
109+
}
110+
111+
/**
112+
* Set status to selected items
113+
*
114+
* @param array $selected
115+
* @return void
116+
* @throws \Exception
117+
*/
118+
protected function selectedSetStatus(array $selected)
119+
{
120+
/** @var AbstractCollection $collection */
121+
$collection = $this->_objectManager->get($this->collection);
122+
$collection->addFieldToFilter(static::ID_FIELD, ['in' => $selected]);
123+
$this->setStatus($collection);
124+
}
125+
126+
/**
127+
* Set status to collection items
128+
*
129+
* @param AbstractCollection $collection
130+
* @return void
131+
*/
132+
protected function setStatus(AbstractCollection $collection)
133+
{
134+
foreach ($collection->getAllIds() as $id) {
135+
/** @var \Magento\Framework\Model\AbstractModel $model */
136+
$model = $this->_objectManager->get($this->model);
137+
$model->load($id);
138+
$model->setIsActive($this->status);
139+
$model->save();
140+
}
141+
}
142+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Cms\Controller\Adminhtml\Page;
7+
8+
use Magento\Cms\Controller\Adminhtml\AbstractMassStatus;
9+
10+
/**
11+
* Class MassDisable
12+
*/
13+
class MassDisable extends AbstractMassStatus
14+
{
15+
/**
16+
* Field id
17+
*/
18+
const ID_FIELD = 'page_id';
19+
20+
/**
21+
* Resource collection
22+
*
23+
* @var string
24+
*/
25+
protected $collection = 'Magento\Cms\Model\Resource\Page\Collection';
26+
27+
/**
28+
* Page model
29+
*
30+
* @var string
31+
*/
32+
protected $model = 'Magento\Cms\Model\Page';
33+
34+
/**
35+
* Page disable status
36+
*
37+
* @var boolean
38+
*/
39+
protected $status = false;
40+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Cms\Controller\Adminhtml\Page;
7+
8+
use Magento\Cms\Controller\Adminhtml\AbstractMassStatus;
9+
10+
/**
11+
* Class MassEnable
12+
*/
13+
class MassEnable extends AbstractMassStatus
14+
{
15+
/**
16+
* Field id
17+
*/
18+
const ID_FIELD = 'page_id';
19+
20+
/**
21+
* Resource collection
22+
*
23+
* @var string
24+
*/
25+
protected $collection = 'Magento\Cms\Model\Resource\Page\Collection';
26+
27+
/**
28+
* Page model
29+
*
30+
* @var string
31+
*/
32+
protected $model = 'Magento\Cms\Model\Page';
33+
34+
/**
35+
* Page enable status
36+
*
37+
* @var boolean
38+
*/
39+
protected $status = true;
40+
}

app/code/Magento/Cms/Model/Page/Source/IsActive.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ public function __construct(\Magento\Cms\Model\Page $cmsPage)
3434
*/
3535
public function toOptionArray()
3636
{
37-
$options = [];
37+
$options[] = ['label' => '', 'value' => ''];
3838
$availableOptions = $this->cmsPage->getAvailableStatuses();
3939
foreach ($availableOptions as $key => $value) {
40-
$options[$key] = [
40+
$options[] = [
4141
'label' => $value,
4242
'value' => $key,
4343
];

app/code/Magento/Cms/Model/Page/Source/PageLayout.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ public function toOptionArray()
4343
if ($this->options !== null) {
4444
return $this->options;
4545
}
46-
$options = [];
46+
$options[] = ['label' => '', 'value' => ''];
4747
$configOptions = $this->pageLayoutBuilder->getPageLayoutsConfig()->getOptions();
4848
foreach ($configOptions as $key => $value) {
49-
$options[$key] = [
49+
$options[] = [
5050
'label' => $value,
5151
'value' => $key,
5252
];
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Cms\Model\Page\Source;
7+
8+
use Magento\Framework\Data\OptionSourceInterface;
9+
use Magento\Framework\View\Design\Theme\Label\ListInterface;
10+
11+
/**
12+
* Class Theme
13+
*/
14+
class Theme implements OptionSourceInterface
15+
{
16+
/**
17+
* @var \Magento\Framework\View\Design\Theme\Label\ListInterface
18+
*/
19+
protected $themeList;
20+
21+
/**
22+
* Constructor
23+
*
24+
* @param ListInterface $themeList
25+
*/
26+
public function __construct(ListInterface $themeList)
27+
{
28+
$this->themeList = $themeList;
29+
}
30+
31+
/**
32+
* Get options
33+
*
34+
* @return array
35+
*/
36+
public function toOptionArray()
37+
{
38+
$options[] = ['label' => '', 'value' => ''];
39+
return $options + $this->themeList->getLabels();
40+
41+
}
42+
}

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

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,16 @@
245245
<item name="label" xsi:type="string" translate="true">Delete</item>
246246
<item name="url" xsi:type="string">cms/page/massDelete</item>
247247
</item>
248+
<item name="disable" xsi:type="array">
249+
<item name="type" xsi:type="string">disable</item>
250+
<item name="label" xsi:type="string" translate="true">Disable</item>
251+
<item name="url" xsi:type="string">cms/page/massDisable</item>
252+
</item>
253+
<item name="enable" xsi:type="array">
254+
<item name="type" xsi:type="string">enable</item>
255+
<item name="label" xsi:type="string" translate="true">Enable</item>
256+
<item name="url" xsi:type="string">cms/page/massEnable</item>
257+
</item>
248258
</item>
249259
<item name="indexField" xsi:type="string">page_id</item>
250260
</item>
@@ -410,6 +420,88 @@
410420
</item>
411421
</argument>
412422
</column>
423+
<column name="custom_theme_from">
424+
<argument name="data" xsi:type="array">
425+
<item name="js_config" xsi:type="array">
426+
<item name="component" xsi:type="string">Magento_Ui/js/grid/columns/date</item>
427+
</item>
428+
<item name="config" xsi:type="array">
429+
<item name="dataType" xsi:type="string">date</item>
430+
<item name="align" xsi:type="string">left</item>
431+
<item name="label" xsi:type="string" translate="true">Custom design from</item>
432+
<item name="dateFormat" xsi:type="string">MMM d, y</item>
433+
<item name="visible" xsi:type="boolean">false</item>
434+
</item>
435+
</argument>
436+
</column>
437+
<column name="custom_theme_to">
438+
<argument name="data" xsi:type="array">
439+
<item name="js_config" xsi:type="array">
440+
<item name="component" xsi:type="string">Magento_Ui/js/grid/columns/date</item>
441+
</item>
442+
<item name="config" xsi:type="array">
443+
<item name="dataType" xsi:type="string">date</item>
444+
<item name="align" xsi:type="string">left</item>
445+
<item name="label" xsi:type="string" translate="true">Custom design to</item>
446+
<item name="dateFormat" xsi:type="string">MMM d, y</item>
447+
<item name="visible" xsi:type="boolean">false</item>
448+
</item>
449+
</argument>
450+
</column>
451+
<column name="custom_theme">
452+
<argument name="data" xsi:type="array">
453+
<item name="options" xsi:type="object">Magento\Cms\Model\Page\Source\Theme</item>
454+
<item name="js_config" xsi:type="array">
455+
<item name="component" xsi:type="string">Magento_Ui/js/grid/columns/select</item>
456+
</item>
457+
<item name="config" xsi:type="array">
458+
<item name="dataType" xsi:type="string">select</item>
459+
<item name="align" xsi:type="string">left</item>
460+
<item name="label" xsi:type="string" translate="true">Custom Theme</item>
461+
<item name="visible" xsi:type="boolean">false</item>
462+
</item>
463+
</argument>
464+
</column>
465+
<column name="custom_root_template">
466+
<argument name="data" xsi:type="array">
467+
<item name="options" xsi:type="object">Magento\Cms\Model\Page\Source\PageLayout</item>
468+
<item name="js_config" xsi:type="array">
469+
<item name="component" xsi:type="string">Magento_Ui/js/grid/columns/select</item>
470+
</item>
471+
<item name="config" xsi:type="array">
472+
<item name="dataType" xsi:type="string">select</item>
473+
<item name="align" xsi:type="string">left</item>
474+
<item name="label" xsi:type="string" translate="true">Custom Layout</item>
475+
<item name="visible" xsi:type="boolean">false</item>
476+
</item>
477+
</argument>
478+
</column>
479+
<column name="meta_keywords">
480+
<argument name="data" xsi:type="array">
481+
<item name="js_config" xsi:type="array">
482+
<item name="component" xsi:type="string">Magento_Ui/js/grid/columns/sortable</item>
483+
</item>
484+
<item name="config" xsi:type="array">
485+
<item name="dataType" xsi:type="string">text</item>
486+
<item name="align" xsi:type="string">left</item>
487+
<item name="label" xsi:type="string" translate="true">Meta Keywords</item>
488+
<item name="visible" xsi:type="boolean">false</item>
489+
</item>
490+
</argument>
491+
</column>
492+
<column name="meta_description">
493+
<argument name="data" xsi:type="array">
494+
<item name="js_config" xsi:type="array">
495+
<item name="component" xsi:type="string">Magento_Ui/js/grid/columns/sortable</item>
496+
</item>
497+
<item name="config" xsi:type="array">
498+
<item name="dataType" xsi:type="string">text</item>
499+
<item name="align" xsi:type="string">left</item>
500+
<item name="label" xsi:type="string" translate="true">Meta Description</item>
501+
<item name="visible" xsi:type="boolean">false</item>
502+
</item>
503+
</argument>
504+
</column>
413505
<column name="actions" class="Magento\Cms\Ui\Component\Listing\Column\PageActions">
414506
<argument name="data" xsi:type="array">
415507
<item name="config" xsi:type="array">

0 commit comments

Comments
 (0)