0

I am trying to list some records using the listing UI-Component and i have a Collection like:

class Collection extends \Magento\Sales\Model\ResourceModel\Order\Shipment\Track\Collection 
{

    public function __construct(
        \Magento\Framework\Data\Collection\EntityFactoryInterface $entityFactory,
        \Psr\Log\LoggerInterface $logger,
        \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy,
        \Magento\Framework\Event\ManagerInterface $eventManager,
        \Magento\Framework\Model\ResourceModel\Db\VersionControl\Snapshot $entitySnapshot,
        \Magento\Store\Model\StoreManagerInterface $storeManager,        
         $mainTable,
        $eventPrefix,
        $eventObject,
        $resourceModel,
        $model = 'Magento\Framework\View\Element\UiComponent\DataProvider\Document',
        $connection = null,
        \Magento\Framework\Model\ResourceModel\Db\AbstractDb $resource = null       
    ) {
        $this->entitySnapshot = $entitySnapshot;
        parent::__construct(
            $entityFactory,
            $logger,
            $fetchStrategy,
            $eventManager,
            $connection,
            $resource
        );
        $this->_eventPrefix = $eventPrefix;
        $this->_eventObject = $eventObject;
        $this->_init($model, $resourceModel);
        $this->setMainTable($mainTable);
    }

The above class is instatiated in my di.xml:

<type name="Magento\Framework\View\Element\UiComponent\DataProvider\CollectionFactory">
        <arguments>
            <argument name="collections" xsi:type="array">
                <item name="shiptracker_tracking_listing_data_source" xsi:type="string">Vendor\MyModule\Model\ResourceModel\Tracking\Grid\Collection</item>
            </argument>
        </arguments>
    </type>    
<type name="Vendor\MyModule\Model\ResourceModel\Tracking\Grid\Collection">
            <arguments>         
                <argument name="mainTable" xsi:type="string">sales_shipment_track</argument>
                <argument name="eventPrefix" xsi:type="string">sales_shipment_track_collection</argument>
                <argument name="eventObject" xsi:type="string">sales_shipment_track_collection</argument>
                <argument name="resourceModel" xsi:type="string">Magento\Sales\Model\ResourceModel\Order\Shipment\Track</argument>
            </arguments>
        </type>

My problem is that when i am trying to access the listing page, i am getting the following error:

Recoverable Error: Argument 5 passed to Magento\Framework\Model\ResourceModel\Db\VersionControl\Collection::__construct() must be an instance of Magento\Framework\Model\ResourceModel\Db\VersionControl\Snapshot, null given, called in /var/www/html/magento2/app/code/Vendor/MyModule/Model/ResourceModel/Tracking/Grid/Collection.php on line 56 and defined in /var/www/html/magento2/lib/internal/Magento/Framework/Model/ResourceModel/Db/VersionControl/Collection.php on line 32

The same constructor seems to be used by other collections without any issue.

2
  • remove var/cache and var/generation folder and try again
    – ND17
    Commented Apr 26, 2016 at 10:35
  • Unfortunately it did not help
    – Sakis
    Commented Apr 26, 2016 at 10:58

1 Answer 1

0

The problem was caused in the calling of the parent constructor:

  parent::__construct(
            $entityFactory,
            $logger,
            $fetchStrategy,
            $eventManager,
            $connection,
            $resource
        );

Was missing the $entitySnapshot param. The correct is:

   parent::__construct(
        $entityFactory,
        $logger,
        $fetchStrategy,
        $eventManager,
        $entitySnapshot,
        $connection,
        $resource
    );

Your Answer

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

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