I don't understand what is wrong with this Renderer code:
<?php
namespace Darsh\Banner\Block\Adminhtml\Grid\Renderer;
use Magento\Framework\DataObject as DObject;
use Magento\Framework\Data\Form\Element\Renderer\RendererInterface as RI;
use Magento\Framework\Data\Form\Element\AbstractElement as AE;
use Magento\Backend\Block\Widget\Grid\Column\Renderer\AbstractRenderer as AR;
class ImageView extends AE implements RI
{
## public function render(\Magento\Framework\Object $row)
public function render(DObject $row)
{
echo "<pre/>";print_r($row);die;
}
}
Whenever I compile my code with this in "Darsh_Banner" module, it generates fatal error in "Repositories Code Generation:" step as below:
PHP Fatal error: Declaration of Darsh\Banner\Block\Adminhtml\Grid\Renderer\ImageView::render() must be compatible with Magento\Framework\Data\Form\Element\Renderer\RendererInterface::render(Magento\Framework\Data\Form\Element\AbstractElement $element) in /var/www/html/magento-2/app/code/Darsh/Banner/Block/Adminhtml/Banner/Grid/Renderer/ImageView.php on line 9
Grid.php of Darsh-Banner module:
<?php
namespace Darsh\Banner\Block\Adminhtml\Banner;
class Grid extends \Magento\Backend\Block\Widget\Grid\Extended
{
/**
* @var \Magento\Framework\Module\Manager
*/
protected $moduleManager;
/**
* @var \Darsh\Banner\Model\bannerFactory
*/
protected $_bannerFactory;
/**
* @var \Darsh\Banner\Model\Status
*/
protected $_status;
/**
* @param \Magento\Backend\Block\Template\Context $context
* @param \Magento\Backend\Helper\Data $backendHelper
* @param \Darsh\Banner\Model\bannerFactory $bannerFactory
* @param \Darsh\Banner\Model\Status $status
* @param \Magento\Framework\Module\Manager $moduleManager
* @param array $data
*
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
public function __construct(
\Magento\Backend\Block\Template\Context $context,
\Magento\Backend\Helper\Data $backendHelper,
\Darsh\Banner\Model\BannerFactory $bannerFactory,
\Darsh\Banner\Model\Status $status,
\Magento\Framework\Module\Manager $moduleManager,
array $data = []
) {
$this->_bannerFactory = $bannerFactory;
$this->_status = $status;
$this->moduleManager = $moduleManager;
parent::__construct($context, $backendHelper, $data);
}
/**
* @return void
*/
protected function _construct()
{
parent::_construct();
$this->setId('postGrid');
$this->setDefaultSort('banner_id');
$this->setDefaultDir('DESC');
$this->setSaveParametersInSession(true);
$this->setUseAjax(true);
$this->setVarNameFilter('post_filter');
}
/**
* @return $this
*/
protected function _prepareCollection()
{
$collection = $this->_bannerFactory->create()->getCollection();
$this->setCollection($collection);
parent::_prepareCollection();
return $this;
}
/**
* @return $this
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
protected function _prepareColumns()
{
$this->addColumn(
'banner_id',
[
'header' => __('ID'),
'type' => 'number',
'index' => 'banner_id',
'header_css_class' => 'col-id',
'column_css_class' => 'col-id'
]
);
$this->addColumn(
'title',
[
'header' => __('Title'),
'index' => 'title',
'class' => 'xxx'
]
);
$this->addColumn(
'image',
[
'header' => __('Image'),
'index' => 'image',
'class' => 'xxx',
## 'renderer' => 'Darsh\Banner\Block\Adminhtml\Banner\Grid\Renderer\ImageView'
]
);
$this->addColumn(
'is_active',
[
'header' => __('Status'),
'index' => 'is_active',
'type' => 'options',
'options' => $this->_status->getOptionArray()
]
);
$this->addColumn(
'edit',
[
'header' => __('Edit'),
'type' => 'action',
'getter' => 'getId',
'actions' => [
[
'caption' => __('Edit'),
'url' => [
'base' => '*/*/edit'
],
'field' => 'banner_id'
]
],
'filter' => false,
'sortable' => false,
'index' => 'stores',
'header_css_class' => 'col-action',
'column_css_class' => 'col-action'
]
);
$block = $this->getLayout()->getBlock('grid.bottom.links');
if ($block) {
$this->setChild('grid.bottom.links', $block);
}
return parent::_prepareColumns();
}
/**
* @return $this
*/
protected function _prepareMassaction()
{
$this->setMassactionIdField('banner_id');
$this->getMassactionBlock()->setTemplate('Darsh_Banner::banner/grid/massaction_extended.phtml');
$this->getMassactionBlock()->setFormFieldName('banner');
$this->getMassactionBlock()->addItem(
'delete',
[
'label' => __('Delete'),
'url' => $this->getUrl('banner/*/massDelete'),
'confirm' => __('Are you sure?')
]
);
$statuses = $this->_status->getOptionArray();
$this->getMassactionBlock()->addItem(
'status',
[
'label' => __('Change status'),
'url' => $this->getUrl('banner/*/massStatus', ['_current' => true]),
'additional' => [
'visibility' => [
'name' => 'status',
'type' => 'select',
'class' => 'required-entry',
'label' => __('Status'),
'values' => $statuses
]
]
]
);
return $this;
}
/**
* @return string
*/
public function getGridUrl()
{
return $this->getUrl('banner/*/grid', ['_current' => true]);
}
/**
* @param \Darsh\Banner\Model\banner|\Magento\Framework\Object $row
* @return string
*/
public function getRowUrl($row)
{
return $this->getUrl(
'banner/*/edit',
['banner_id' => $row->getId()]
);
}
}
I tried changing "implementing from" classes but same error.
Anyone please provide suggestion.