1

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

  • Run bin/magento setup:upgrade or clear generated folder (don't delete .htaccess) – Anshu Mishra Sep 6 '18 at 13:16
  • Yep run bin/magento setup:upgrade has solved my issue. Thanks. – Jakk64 Sep 12 '18 at 10:19
0

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);
}
  • Thanks for your help, run bin/magento setup:upgrade has solved my issue. – Jakk64 Sep 12 '18 at 10:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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