Question

I added a custom mass action to the shipments grid for sending multiple tracking emails at once and the collection part is throwing an error, because I must be missing something.

For reference, I looked at the Magento\Cms\Controller\Adminhtml\Page\MassDisable class. So I came up with this:

/app/code/PerunPro/DPD/Controller/Adminhtml/Shipment/MassSendTracking.php

<?php
namespace PerunPro\DPD\Controller\Adminhtml\Shipment;

use Magento\Backend\App\Action\Context;
use Magento\Framework\Controller\ResultFactory;
use Magento\Sales\Api\ShipmentManagementInterface;
use Magento\Sales\Model\ResourceModel\Order\Shipment\CollectionFactory;
use Magento\Ui\Component\MassAction\Filter;

class MassSendTracking extends \Magento\Backend\App\Action
{
    /**
     * Authorization level of a basic admin session
     *
     * @see _isAllowed()
     */
    const ADMIN_RESOURCE = 'Magento_Sales::shipment';

    /**
     * @var Filter
     */
    protected $filter;

    /**
     * @var CollectionFactory
     */
    protected $collectionFactory;

    protected $shipmentManagement;

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

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

        // Do stuff

        /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
        $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
        return $resultRedirect->setPath('*/*/');
    }
}

When I submit the request, I get the following error:

Fatal error: Uncaught TypeError: Argument 2 passed to Magento\Framework\View\Element\UiComponentFactory::argumentsResolver() must be of the type array, null given, called in /var/www/magento/v2_2/vendor/magento/framework/View/Element/UiComponentFactory.php on line 198 and defined in /var/www/magento/v2_2/vendor/magento/framework/View/Element/UiComponentFactory.php on line 164

I am guessing I am missing some stuff in di.xml, because Magento\Sales\Model\ResourceModel\Order\Shipment\CollectionFactory does not exist, but so doesn't Magento\Cms\Model\ResourceModel\Page\CollectionFactory which is in Page\MassDisable. The CMS di.xml has this about it:

<type name="Magento\Framework\View\Element\UiComponent\DataProvider\CollectionFactory">
        <arguments>
            <argument name="collections" xsi:type="array">
                <item name="cms_page_listing_data_source" xsi:type="string">Magento\Cms\Model\ResourceModel\Page\Grid\Collection</item>
                <item name="cms_block_listing_data_source" xsi:type="string">Magento\Cms\Model\ResourceModel\Block\Grid\Collection</item>
            </argument>
        </arguments>
    </type>

So I tried with with a wild guess in my own di.xml:

<type name="Magento\Framework\View\Element\UiComponent\DataProvider\CollectionFactory">
        <arguments>
            <argument name="collections" xsi:type="array">
                <item name="sales_order_shipment_grid_data_source" xsi:type="string">Magento\Sales\Model\ResourceModel\Order\Shipment\Grid\Collection</item>
            </argument>
        </arguments>
    </type>

Which of course has no effect :) Please help.

My module.xml sequence, I thought it would mean it also loads the XML grid info but clearly it doesn't

<sequence>
    <module name="Magento_Sales"/>
    <module name="Magento_Shipping"/>
</sequence>
Was it helpful?

Solution

I figured it out... Since I wanted to continue on this and tried to debug it, I noticed that today it works.

While I was working on other stuff, I ran the setup:di:compile command several times in CLI. I think this is what was missing from the above. Also, the stuff in di.xml is not needed.

OTHER TIPS

I had this issue when I was referencing a ui component in an incorrectly named folder. I had it as view/adminhtml/uiComponent when it should be view/adminhtml/ui_component.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top