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 
9 use Magento\CheckoutAgreements\Model\ResourceModel\Agreement\Grid\CollectionFactory as GridCollectionFactory;
10 
11 class Grid extends \Magento\Backend\Block\Widget\Grid\Extended
12 {
18 
22  private $gridCollectionFactory;
23 
32  public function __construct(
33  \Magento\Backend\Block\Template\Context $context,
34  \Magento\Backend\Helper\Data $backendHelper,
35  \Magento\CheckoutAgreements\Model\ResourceModel\Agreement\CollectionFactory $collectionFactory,
36  array $data = [],
37  GridCollectionFactory $gridColFactory = null
38  ) {
39 
40  $this->_collectionFactory = $collectionFactory;
41  $this->gridCollectionFactory = $gridColFactory
42  ? : ObjectManager::getInstance()->get(GridCollectionFactory::class);
43 
44  parent::__construct($context, $backendHelper, $data);
45  }
46 
50  protected function _construct()
51  {
52  parent::_construct();
53  $this->setDefaultSort('agreement_id');
54  $this->setId('agreementGrid');
55  $this->setDefaultDir('asc');
56  $this->setSaveParametersInSession(true);
57  }
58 
63  protected function _prepareCollection()
64  {
65  $this->setCollection($this->gridCollectionFactory->create());
66  return parent::_prepareCollection();
67  }
68 
72  protected function _prepareColumns()
73  {
74  $this->addColumn(
75  'agreement_id',
76  [
77  'header' => __('ID'),
78  'index' => 'agreement_id',
79  'header_css_class' => 'col-id',
80  'column_css_class' => 'col-id'
81  ]
82  );
83 
84  $this->addColumn(
85  'name',
86  [
87  'header' => __('Condition'),
88  'index' => 'name',
89  'header_css_class' => 'col-name',
90  'column_css_class' => 'col-name'
91  ]
92  );
93 
94  if (!$this->_storeManager->isSingleStoreMode()) {
95  $this->addColumn(
96  'stores',
97  [
98  'header' => __('Store View'),
99  'index' => 'stores',
100  'type' => 'store',
101  'store_all' => true,
102  'store_view' => true,
103  'sortable' => false,
104  'filter_condition_callback' => [$this, '_filterStoreCondition'],
105  'header_css_class' => 'col-store-view',
106  'column_css_class' => 'col-store-view'
107  ]
108  );
109  }
110 
111  $this->addColumn(
112  'is_active',
113  [
114  'header' => __('Status'),
115  'index' => 'is_active',
116  'type' => 'options',
117  'options' => [0 => __('Disabled'), 1 => __('Enabled')],
118  'header_css_class' => 'col-status',
119  'column_css_class' => 'col-status'
120  ]
121  );
122 
123  return parent::_prepareColumns();
124  }
125 
129  protected function _afterLoadCollection()
130  {
131  $this->getCollection()->walk('afterLoad');
132  parent::_afterLoadCollection();
133  }
134 
141  protected function _filterStoreCondition($collection, $column)
142  {
143  if (!($value = $column->getFilter()->getValue())) {
144  return;
145  }
146 
147  $this->getCollection()->addStoreFilter($value);
148  }
149 
155  public function getRowUrl($row)
156  {
157  return $this->getUrl('checkout/*/edit', ['id' => $row->getId()]);
158  }
159 }
__construct(\Magento\Backend\Block\Template\Context $context, \Magento\Backend\Helper\Data $backendHelper, \Magento\CheckoutAgreements\Model\ResourceModel\Agreement\CollectionFactory $collectionFactory, array $data=[], GridCollectionFactory $gridColFactory=null)
Definition: Grid.php:32
__()
Definition: __.php:13
$value
Definition: gender.phtml:16