Question

In Continue with

Magento 2: Error during compilation

I have below error while running

php bin/magento setup:di:compile

Errors during compilation:
        Custom\Module\Model\ResourceModel\Messages\Grid\Collection
                Incompatible argument type: Required type: \Magento\Framework\DB\Adapter\AdapterInterface. Actual type: \Magento\Store\Model\StoreManagerInterface; File:
D:/wamp/www/smint/magento/app/code/Custom/Module/Model/ResourceModel/Messages/Grid/Collection.php

        Custom\Module\Model\ResourceModel\Posts\Grid\Collection
                Incompatible argument type: Required type: \Magento\Framework\DB\Adapter\AdapterInterface. Actual type: \Magento\Store\Model\StoreManagerInterface; File:
D:/wamp/www/smint/magento/app/code/Custom/Module/Model/ResourceModel/Posts/Grid/Collection.php

Total Errors Count: 2

app\code\Custom\Module\Model\ResourceModel\Posts\Grid\Collection.php

namespace Custom\Module\Model\ResourceModel\Posts\Grid;

use Magento\Framework\Api\Search\SearchResultInterface;
use Magento\Framework\Search\AggregationInterface;
use Magento\Framework\DB\Adapter\AdapterInterface;
use Custom\Module\Model\ResourceModel\Posts\Collection as PostsCollection;

/**
 * Collection for displaying grid of etrade posts
 */
class Collection extends PostsCollection implements SearchResultInterface
{
    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\Store\Model\StoreManagerInterface $storeManager,
        \Magento\Framework\EntityManager\MetadataPool $metadataPool,
        $mainTable,
        $eventPrefix,
        $eventObject,
        $resourceModel,
        $model = 'Magento\Framework\View\Element\UiComponent\DataProvider\Document',
        $connection = null,
        \Magento\Framework\Model\ResourceModel\Db\AbstractDb $resource = null
    ) {
        parent::__construct(
            $entityFactory,
            $logger,
            $fetchStrategy,
            $eventManager,
            $storeManager,
            $metadataPool,
            $connection,
            $resource
        );
        $this->_eventPrefix = $eventPrefix;
        $this->_eventObject = $eventObject;
        $this->_init($model, $resourceModel);
        $this->setMainTable($mainTable);
    }
}

app\code\Custom\Module\Model\ResourceModel\Posts\Collection.php

namespace Custom\Module\Model\ResourceModel\Posts;

use Custom\Module\Api\Data\PostsInterface;
use Custom\Module\Model\ResourceModel\AbstractCollection;

class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection {

    protected $_idFieldName = 'posts_id';

    protected function _construct() {
        $this->_init(
                'Custom\Module\Model\Posts', 'Custom\Module\Model\ResourceModel\Posts');
    }

}

How to solve above complication errors?

Was it helpful?

Solution

This is because your parent constructor has redundant arguments or not correct . In your case, need to remove arguments: $storeManager and $metadataPool.

app\code\Custom\Module\Model\ResourceModel\Posts\Grid\Collection.php

parent::__construct(
        $entityFactory,
        $logger,
        $fetchStrategy,
        $eventManager,
        //$storeManager, <= Remove it
        //$metadataPool, <= Remove it
        $connection,
        $resource
    );
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top