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
13 
16 
17 class Grid extends \Magento\Backend\Block\Widget\Grid\Extended
18 {
23 
30  public function __construct(
31  \Magento\Backend\Block\Template\Context $context,
32  \Magento\Backend\Helper\Data $backendHelper,
33  \Magento\Newsletter\Model\ResourceModel\Template\Collection $templateCollection,
34  array $data = []
35  ) {
36  $this->_templateCollection = $templateCollection;
37  parent::__construct($context, $backendHelper, $data);
38  $this->setEmptyText(__('No Templates Found'));
39  }
40 
46  protected function _prepareCollection()
47  {
48  $this->setCollection($this->_templateCollection->useOnlyActual());
49 
50  return parent::_prepareCollection();
51  }
52 
58  protected function _prepareColumns()
59  {
60  $this->addColumn(
61  'template_code',
62  [
63  'header' => __('ID'),
64  'index' => 'template_id',
65  'header_css_class' => 'col-id',
66  'column_css_class' => 'col-id'
67  ]
68  );
69  $this->addColumn(
70  'code',
71  [
72  'header' => __('Template'),
73  'index' => 'template_code',
74  'header_css_class' => 'col-template',
75  'column_css_class' => 'col-template'
76  ]
77  );
78 
79  $this->addColumn(
80  'added_at',
81  [
82  'header' => __('Added'),
83  'index' => 'added_at',
84  'gmtoffset' => true,
85  'type' => 'datetime',
86  'header_css_class' => 'col-added col-date',
87  'column_css_class' => 'col-added col-date'
88  ]
89  );
90 
91  $this->addColumn(
92  'modified_at',
93  [
94  'header' => __('Updated'),
95  'index' => 'modified_at',
96  'gmtoffset' => true,
97  'type' => 'datetime',
98  'header_css_class' => 'col-updated col-date',
99  'column_css_class' => 'col-updated col-date'
100  ]
101  );
102 
103  $this->addColumn(
104  'subject',
105  [
106  'header' => __('Subject'),
107  'index' => 'template_subject',
108  'header_css_class' => 'col-subject',
109  'column_css_class' => 'col-subject'
110  ]
111  );
112 
113  $this->addColumn(
114  'sender',
115  [
116  'header' => __('Sender'),
117  'index' => 'template_sender_email',
118  'renderer' => \Magento\Newsletter\Block\Adminhtml\Template\Grid\Renderer\Sender::class,
119  'header_css_class' => 'col-sender',
120  'column_css_class' => 'col-sender'
121  ]
122  );
123 
124  $this->addColumn(
125  'type',
126  [
127  'header' => __('Template Type'),
128  'index' => 'template_type',
129  'type' => 'options',
130  'options' => [
131  TemplateTypesInterface::TYPE_HTML => 'html',
132  TemplateTypesInterface::TYPE_TEXT => 'text',
133  ],
134  'header_css_class' => 'col-type',
135  'column_css_class' => 'col-type'
136  ]
137  );
138 
139  $this->addColumn(
140  'action',
141  [
142  'header' => __('Action'),
143  'index' => 'template_id',
144  'sortable' => false,
145  'filter' => false,
146  'no_link' => true,
147  'renderer' => \Magento\Newsletter\Block\Adminhtml\Template\Grid\Renderer\Action::class,
148  'header_css_class' => 'col-actions',
149  'column_css_class' => 'col-actions'
150  ]
151  );
152 
153  return $this;
154  }
155 
162  public function getRowUrl($row)
163  {
164  return $this->getUrl('*/*/edit', ['id' => $row->getId()]);
165  }
166 }
__()
Definition: __.php:13
__construct(\Magento\Backend\Block\Template\Context $context, \Magento\Backend\Helper\Data $backendHelper, \Magento\Newsletter\Model\ResourceModel\Template\Collection $templateCollection, array $data=[])
Definition: Grid.php:30