3

I'm using Magento 2.3.3.

I created a plugin that can edit product at the frontend. The plugin works fine. But it error when running setup:di:compile.

Incompatible argument type: Required type: \Magento\Framework\Escaper. Actual type: array; File:.../app/code/.../xxx.php

Here is my code,

class Edit extends \Magento\Catalog\Block\Adminhtml\Product\Edit
{
    public function __construct(
        \Magento\Backend\Block\Template\Context $context,
        \Magento\Framework\Json\EncoderInterface $jsonEncoder,
        \Magento\Eav\Model\Entity\Attribute\SetFactory $attributeSetFactory,
        \Magento\Framework\Registry $registry,
        \Magento\Catalog\Helper\Product $productHelper,
        array $data = []
    ) {
        $this->_productHelper = $productHelper;
        $this->_attributeSetFactory = $attributeSetFactory;
        $this->_coreRegistry = $registry;
        $this->jsonEncoder = $jsonEncoder;

        parent::__construct($context,
        $jsonEncoder,$attributeSetFactory,$registry,$productHelper,$data);
        $this->setData('area','adminhtml');
    }
    protected function _construct()
    {
        parent::_construct();
        $this->setId('product_edit');
        $this->setUseContainer(true);
    }

    public function getProduct()
    {
     ...................

Please help. Thank you

1 Answer 1

4

Replace __construct method with below code.

public function __construct(
    \Magento\Backend\Block\Template\Context $context,
    \Magento\Framework\Json\EncoderInterface $jsonEncoder,
    \Magento\Eav\Model\Entity\Attribute\SetFactory $attributeSetFactory,
    \Magento\Framework\Registry $registry,
    \Magento\Catalog\Helper\Product $productHelper,
    \Magento\Framework\Escaper $escaper,
    array $data = []
) {
    $this->_productHelper = $productHelper;
    $this->_attributeSetFactory = $attributeSetFactory;
    $this->_coreRegistry = $registry;
    $this->jsonEncoder = $jsonEncoder;
    parent::__construct($context, $jsonEncoder, $attributeSetFactory, $registry, $productHelper, $escaper, $data);
    $this->setData('area','adminhtml');
}

Execute:

php bin/magento setup:di:compile
php bin/magento cache:clean
1

Your Answer

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

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