Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Grid.php
Go to the documentation of this file.
1 <?php
7 
11 class Grid extends \Magento\Backend\Block\Widget\Grid\Extended
12 {
17 
21  protected $_cmsPage;
22 
26  protected $pageLayoutBuilder;
27 
36  public function __construct(
37  \Magento\Backend\Block\Template\Context $context,
38  \Magento\Backend\Helper\Data $backendHelper,
39  \Magento\Cms\Model\Page $cmsPage,
40  \Magento\Cms\Model\ResourceModel\Page\CollectionFactory $collectionFactory,
41  \Magento\Framework\View\Model\PageLayout\Config\BuilderInterface $pageLayoutBuilder,
42  array $data = []
43  ) {
44  $this->_collectionFactory = $collectionFactory;
45  $this->_cmsPage = $cmsPage;
46  $this->pageLayoutBuilder = $pageLayoutBuilder;
47  parent::__construct($context, $backendHelper, $data);
48  }
49 
53  protected function _construct()
54  {
55  parent::_construct();
56  $this->setId('cmsPageGrid');
57  $this->setDefaultSort('identifier');
58  $this->setDefaultDir('ASC');
59  }
60 
66  protected function _prepareCollection()
67  {
68  $collection = $this->_collectionFactory->create();
69  /* @var $collection \Magento\Cms\Model\ResourceModel\Page\Collection */
70  $collection->setFirstStoreFlag(true);
71  $this->setCollection($collection);
72 
73  return parent::_prepareCollection();
74  }
75 
81  protected function _prepareColumns()
82  {
83  $this->addColumn('title', ['header' => __('Title'), 'index' => 'title']);
84 
85  $this->addColumn('identifier', ['header' => __('URL Key'), 'index' => 'identifier']);
86 
87  $this->addColumn(
88  'page_layout',
89  [
90  'header' => __('Layout'),
91  'index' => 'page_layout',
92  'type' => 'options',
93  'options' => $this->pageLayoutBuilder->getPageLayoutsConfig()->getOptions()
94  ]
95  );
96 
100  if (!$this->_storeManager->isSingleStoreMode()) {
101  $this->addColumn(
102  'store_id',
103  [
104  'header' => __('Store View'),
105  'index' => 'store_id',
106  'type' => 'store',
107  'store_all' => true,
108  'store_view' => true,
109  'sortable' => false,
110  'filter_condition_callback' => [$this, '_filterStoreCondition']
111  ]
112  );
113  }
114 
115  $this->addColumn(
116  'is_active',
117  [
118  'header' => __('Status'),
119  'index' => 'is_active',
120  'type' => 'options',
121  'options' => $this->_cmsPage->getAvailableStatuses()
122  ]
123  );
124 
125  $this->addColumn(
126  'creation_time',
127  [
128  'header' => __('Created'),
129  'index' => 'creation_time',
130  'type' => 'datetime',
131  'header_css_class' => 'col-date',
132  'column_css_class' => 'col-date'
133  ]
134  );
135 
136  $this->addColumn(
137  'update_time',
138  [
139  'header' => __('Modified'),
140  'index' => 'update_time',
141  'type' => 'datetime',
142  'header_css_class' => 'col-date',
143  'column_css_class' => 'col-date'
144  ]
145  );
146 
147  $this->addColumn(
148  'page_actions',
149  [
150  'header' => __('Action'),
151  'sortable' => false,
152  'filter' => false,
153  'renderer' => \Magento\Cms\Block\Adminhtml\Page\Grid\Renderer\Action::class,
154  'header_css_class' => 'col-action',
155  'column_css_class' => 'col-action'
156  ]
157  );
158 
159  return parent::_prepareColumns();
160  }
161 
167  protected function _afterLoadCollection()
168  {
169  $this->getCollection()->walk('afterLoad');
170  parent::_afterLoadCollection();
171  }
172 
181  protected function _filterStoreCondition($collection, \Magento\Framework\DataObject $column)
182  {
183  if (!($value = $column->getFilter()->getValue())) {
184  return;
185  }
186 
187  $this->getCollection()->addStoreFilter($value);
188  }
189 
196  public function getRowUrl($row)
197  {
198  return $this->getUrl('*/*/edit', ['page_id' => $row->getId()]);
199  }
200 }
__()
Definition: __.php:13
__construct(\Magento\Backend\Block\Template\Context $context, \Magento\Backend\Helper\Data $backendHelper, \Magento\Cms\Model\Page $cmsPage, \Magento\Cms\Model\ResourceModel\Page\CollectionFactory $collectionFactory, \Magento\Framework\View\Model\PageLayout\Config\BuilderInterface $pageLayoutBuilder, array $data=[])
Definition: Grid.php:36
$value
Definition: gender.phtml:16
_filterStoreCondition($collection, \Magento\Framework\DataObject $column)
Definition: Grid.php:181