Question

I'm getting strange error when I want to use mass action in a grid :

AH01071: Got error 'PHP message: PHP Fatal error:  Uncaught TypeError: Argument 2 passed to Toto\\Helloworld\\Controller\\Adminhtml\\Page\\MassDelete::__construct() must be an instance of Magento\\Ui\\Component\\MassAction\\Filter, none given

See my Controller MassAction file :

namespace Toto\Helloworld\Controller\Adminhtml\Page;

use Magento\Framework\Controller\ResultFactory;
use Magento\Backend\App\Action\Context;
use Magento\Ui\Component\MassAction\Filter;
use Toto\Helloworld\Model\ResourceModel\Contact\CollectionFactory;

class MassDelete extends \Magento\Backend\App\Action
{
protected $filter;
protected $collectionFactory;

public function __construct(Context $context, Filter $filter, CollectionFactory $collectionFactory)
{
    $this->filter = $filter;
    $this->collectionFactory = $collectionFactory;
    parent::__construct($context);
}

public function execute()
{
    $collection = $this->filter->getCollection($this->collectionFactory->create());
    $collectionSize = $collection->getSize();

    foreach ($collection as $contact) {
        $contact->delete();
    }

    $this->messageManager->addSuccess(__('A total of %1 record(s) have been deleted.', $collectionSize));

    $resultRedirect = $this->resultRedirectFactory->create();
    return $resultRedirect->setPath('*/*/index', array('_current' => true));
}
}

Do you know why ? It looks like the namespace use Magento\Ui\Component\MassAction\Filter; is not detected. Thanks in advance

Était-ce utile?

La solution

Replace your constructor with following then remove your module from generated folder. You can find this folder on root of your magento for Magento 2.2

public function __construct(Context $context, Filter $filter, CollectionFactory $collectionFactory)
{
    $this->filter = $filter;
    $this->collectionFactory = $collectionFactory;
    parent::__construct($context, $filter, $collectionFactory);
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à magento.stackexchange
scroll top