2

Fatal error: Declaration of \ModuleName\Block\Adminhtml\ModuleName\Grid\Renderer\Image::render() must be compatible with Magento\Backend\Block\Widget\Grid\Column\Renderer\RendererInterface::render(Magento\Framework\DataObject $row) in C:\wamp\www\magento2\app\code\\ModuleName\Block\Adminhtml\ModuleName\Grid\Renderer\Image.php on line 59

<?php
namespace <vendor-name>\ModuleName\Block\Adminhtml\ModuleName\Grid\Renderer;
use Magento\Backend\Block\Widget\Grid\Column\Renderer\AbstractRenderer;
use Magento\Framework\Object;
use Magento\Store\Model\StoreManagerInterface;
class Image extends AbstractRenderer
{
 private $_storeManager;
 /**
 * @param \Magento\Backend\Block\Context $context
 * @param array $data
 */
 public function __construct(\Magento\Backend\Block\Context $context, StoreManagerInterface $storemanager, array $data = [])
 {
 $this->_storeManager = $storemanager;
 parent::__construct($context, $data);
 $this->_authorization = $context->getAuthorization();
 echo "test";
 }
 /**
 * Renders grid column
 *
 * @param Object $row
 * @return string
 */
 public function render(Object $row)
 {
 $mediaDirectory = $this->_storeManager->getStore()->getBaseUrl(
 \Magento\Framework\UrlInterface::URL_TYPE_MEDIA
 );
 $imageUrl = $mediaDirectory.'/FolderPathName'.$this->_getValue($row);
 return '<img src="'.$imageUrl.'" width="50"/>';
 }
}
Raphael at Digital Pianism
70.8k37 gold badges192 silver badges357 bronze badges
asked Apr 9, 2016 at 4:59
1
  • 2
    PHP expects, that the method signature is the same for a child class. Commented Apr 9, 2016 at 8:42

1 Answer 1

2

As stated by Fabian in the comment your child class method signature is different from the parent class.

The parent method from AbstractRenderer is

public function render(DataObject $row)
{
 if ($this->getColumn()->getEditable()) {
 $result = '<div class="admin__grid-control">';
 $result .= $this->getColumn()->getEditOnly() ? ''
 : '<span class="admin__grid-control-value">' . $this->_getValue($row) . '</span>';
 return $result . $this->_getInputValueElement($row) . '</div>' ;
 }
 return $this->_getValue($row);
}

Do you notice the difference with your method?

Your method parameters is Object $row where it should be Magento\Framework\DataObject $row.

answered Apr 9, 2016 at 9:00
2
  • 1
    Additional info. Magento\Framework\Object does not exist anymore. it was turned to Magento\Framework\DataObject to make Magento2 compatible with php7 Commented Apr 9, 2016 at 20:35
  • I am using php 5.6 but still facing the same issue Commented Oct 4, 2016 at 5:16

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.