1

I have used a custom module and when click on the admin configuration module menu throws the error.

This error is facing only in production mode. And faced issue when run php bin/magento setup:di:compile command

if we can run command rm -rf generated/* and run only php bin/magento setup:upgrade then it is working fine.

I have checked this issue is a compilation issue.

Admin custom module menu access error:

Error:

Type Error occurred when creating object: Vendor\Module\Model\ResourceModel\ProductFilterGroup\Grid\Collection\Interceptor, Argument 1 passed to Vendor\Module\Model\ResourceModel\ProductFilterGroup\Grid\Collection\Interceptor::__construct() must implement interface Magento\Framework\App\RequestInterface, instance of Magento\Framework\Data\Collection\EntityFactory given, called in /magento242/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php on line 121
Exception in /magento242/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php:131

File path: Vendor/Module/Model/ResourceModel/ProductFilterGroup/Grid/Collection.php

<?php
namespace Vendor\Module\Model\ResourceModel\ProductFilterGroup\Grid;
use Vendor\Module\Model\ResourceModel\ProductFilterGroup\Collection as GroupAttributeCollection;
use Magento\Framework\Api\Search\AggregationInterface;
use Magento\Framework\Api\Search\SearchResultInterface;
use Magento\Framework\Api\SearchCriteriaInterface;
use Magento\Framework\App\RequestInterface;
use Magento\Framework\Data\Collection\Db\FetchStrategyInterface;
use Magento\Framework\Data\Collection\EntityFactoryInterface;
use Magento\Framework\Event\ManagerInterface;
use Magento\Framework\Model\ResourceModel\Db\AbstractDb;
use Magento\Framework\Serialize\Serializer\Json;
use Magento\Framework\View\Element\UiComponent\DataProvider\Document as GroupAttributeModel;
use Psr\Log\LoggerInterface;
class Collection extends GroupAttributeCollection implements SearchResultInterface
{
 /**
 * @var
 */
 protected $aggregations;
 /**
 * @var RequestInterface
 */
 protected $request;
 /**
 * @var Json
 */
 protected $serializer;
 public function __construct(
 RequestInterface $request,
 Json $serializer,
 EntityFactoryInterface $entityFactory,
 LoggerInterface $logger,
 FetchStrategyInterface $fetchStrategy,
 ManagerInterface $eventManager,
 $mainTable,
 $eventPrefix,
 $eventObject,
 $resourceModel,
 $model = GroupAttributeModel::class,
 $connection = null,
 AbstractDb $resource = null
 ) {
 $this->request = $request;
 $this->serializer = $serializer;
 parent::__construct($entityFactory, $logger, $fetchStrategy, $eventManager, $connection, $resource);
 $this->_eventPrefix = $eventPrefix;
 $this->_eventObject = $eventObject;
 $this->_init($model, $resourceModel);
 $this->setMainTable($mainTable);
 }
 protected function _initSelect()
 {
 parent::_initSelect();
 $this->getSelect()->joinLeft(
 ['secondTable' => $this->getTable('eav_attribute')],
 'main_table.attribute_id = secondTable.attribute_id',
 ['frontend_label as attribute']
 );
 }
 protected function _renderFiltersBefore()
 {
 $filters = $this->request->getParam('filters');
 $storeId = $this->request->getParam('store', 1);
 if (isset($filters['group_title'])) {
 $match = sprintf(
 '%%%s%%',
 substr(
 $this->serializer->serialize([$storeId => $filters['group_title']]),
 1,
 -1
 )
 );
 $this->addFieldToFilter('group_title', ['like' => $match]);
 }
 parent::_renderFiltersBefore();
 }
 public function getAggregations()
 {
 return $this->aggregations;
 }
 
 public function setAggregations($aggregations)
 {
 $this->aggregations = $aggregations;
 }
 
 public function getAllIds($limit = null, $offset = null)
 {
 return $this->getConnection()->fetchCol($this->_getAllIdsSelect($limit, $offset), $this->_bindParams);
 }
 
 public function getSearchCriteria()
 {
 return null;
 }
 
 public function setSearchCriteria(SearchCriteriaInterface $searchCriteria = null)
 {
 return $this;
 }
}

File path: Vendor\Module\Model\ResourceModel\ProductFilterGroup\Collection.php

<?php
namespace Vendor\Module\Model\ResourceModel\ProductFilterGroup;
use Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection;
class Collection extends AbstractCollection
{
 const MODEL = 'Vendor\Module\Model\ProductFilterGroup';
 const RESOURCE_MODEL = 'Vendor\Module\Model\ResourceModel\ProductFilterGroup';
 /**
 * Define resource model
 *
 * @return void
 */
 protected function _construct()
 {
 $this->_init(self::MODEL, self::RESOURCE_MODEL);
 }
}

Does anyone have any idea what is the permanent solution for this issue?

asked Nov 1, 2021 at 6:23
4
  • Can you post your module code, so that we can get some more details and help ? Commented Nov 1, 2021 at 7:17
  • @NarendraVyas I have post module code. please check. Commented Nov 1, 2021 at 9:05
  • Can you post "Vendor\Module\Model\ResourceModel\ProductFilterGroup\Collection" as well. I think there is something wrong in the first parameter that you are passing in parent class constructor. So need to see what is the parent class. Commented Nov 1, 2021 at 10:01
  • @NarendraVyas posted. check now. Commented Nov 1, 2021 at 10:50

1 Answer 1

0

Can you please check class from which you extends this Collection class

According to me Grid/Collection.php class should be extends from "Magento\Framework\View\Element\UiComponent\DataProvider\SearchResult"

answered Nov 1, 2021 at 10:43
1
  • I have checked but not working. Commented Nov 1, 2021 at 12:10

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.