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"/>';
   }
}
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.

2
  • 1
    Additional info. Magento\Framework\Object does not exist anymore. it was turned to Magento\Framework\DataObject to make Magento2 compatible with php7
    – Marius
    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

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.