2

I'm working on a Magento module for the past month, and everything works great on my local machine. Then I decided to release the module as a beta and test it online in a newly installed store, and after installing it from CLI, I'm getting this error:

Werules\Chatbot\Block\Webhook\Messenger Missed required argument request in parent::__construct call. File: /htdocs/magento2/app/code/Werules/Chatbot/Block/Webhook/Messenger.php

Why is that happening? Here is the file app/code/Werules/Chatbot/Block/Webhook/Messenger.php

namespace Werules\Chatbot\Block\Webhook;

class Messenger extends \Werules\Chatbot\Block\Webhook\Index
{
    protected function processRequest()
    {
        // SOME CODE HERE
    }
}

and app/code/Werules/Chatbot/Block/Webhook/Index.php

namespace Werules\Chatbot\Block\Webhook;

class Index extends \Magento\Framework\View\Element\Template
{
    protected $_helper;
    protected $_chatbotAPI;
    protected $_messageModel;
    protected $_objectManager;
    protected $_define;
    protected $_request;

    public function __construct(
        \Magento\Framework\View\Element\Template\Context $context,
        \Magento\Framework\ObjectManagerInterface $objectManager,
        \Werules\Chatbot\Helper\Data $helperData,
        \Werules\Chatbot\Model\ChatbotAPI $chatbotAPI,
        \Magento\Framework\App\Request\Http $request,
        \Werules\Chatbot\Model\MessageFactory $message
    )
    {
        $this->_helper = $helperData;
        $this->_chatbotAPI = $chatbotAPI;
        $this->_request = $request;
        $this->_messageModel = $message;
        $this->_objectManager = $objectManager;
        $this->_define = new \Werules\Chatbot\Helper\Define;
        parent::__construct($context);
    }
}

What I am doing wrong? Thank you.

EDIT: I'm extending another block from my module, is that a bad thing? Maybe this is the problem?

1
  • Did you delete var/generation first?
    – PY Yick
    Dec 1, 2017 at 2:51

1 Answer 1

4

The error is self-explained. You forgot to inject the arguments from the parent. $context and $data are mandatory.

app/code/Werules/Chatbot/Block/Webhook/Index.php

public function __construct(
    \Magento\Framework\View\Element\Template\Context $context, // parent argument
    ......
    array $data = [] // parent argument
) {
    ......
    parent::__construct($context, $data);
}

I'm extending another block from my module, is that a bad thing? Maybe this is the problem?

It's normal.

7
  • Thank you. So I'm missing the data array in the Index block? Because my Messenger block doesn't have a constructor
    – Pablo
    Dec 1, 2017 at 9:56
  • As I see, you're missing in Index.php Dec 1, 2017 at 10:17
  • Is this data array required by Magento? Because I'm not using it in my code. For me it seems that what is missing is "the required argument request in parent::__construct", as I have a \Magento\Framework\App\Request\Http $request as parameter for my Index block.
    – Pablo
    Dec 1, 2017 at 12:10
  • array $data = [] is required by the parent \Magento\Framework\View\Element\Template. Did you try my suggestion? Dec 2, 2017 at 9:03
  • 1
    @Pablo updated my answer. You can update my answer also. Dec 2, 2017 at 21:28

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.