In my custom created module I'm trying to get the grid page in admin working.
I have everything routed, and I'm able to get to the correct page (so i see all of the magento elements, but my grid has an error). When the page is loaded I get the error:
Class Wavelabs\StoreLocator\Model\ResourceModel\Store\Grid\Collection does not exist
My collection code is as followed:
namespace Wavelabs\StoreLocator\Model\ResourceModel\Store\Grid;
use Magento\Framework\Api\Search\SearchResultInterface;
use Magento\Framework\Api\Search\AggregationInterface;
use Wavelabs\StoreLocator\Model\ResourceModel\Store\Collection as StoreCollection;
use \Magento\Framework\Data\Collection\EntityFactoryInterface;
use \Psr\Log\LoggerInterface;
use \Magento\Framework\Data\Collection\Db\FetchStrategyInterface;
use \Magento\Framework\Event\ManagerInterface;
use \Magento\Store\Model\StoreManagerInterface;
use \Magento\Framework\EntityManager\MetadataPool;
use \Magento\Framework\Model\ResourceModel\Db\AbstractDb;
/**
* Class Collection
* Collection for displaying grid of sales documents
*/
class Collection extends StoreCollection implements SearchResultInterface
{
/**
* @var AggregationInterface
*/
protected $aggregations;
/**
* @param EntityFactoryInterface $entityFactory
* @param LoggerInterface $logger
* @param FetchStrategyInterface $fetchStrategy
* @param ManagerInterface $eventManager
* @param StoreManagerInterface $storeManager
* @param MetadataPool $metadataPool
* @param mixed|null $mainTable
* @param \Magento\Framework\Model\ResourceModel\Db\AbstractDb $eventPrefix
* @param mixed $eventObject
* @param mixed $resourceModel
* @param string $model
* @param null $connection
* @param \Magento\Framework\Model\ResourceModel\Db\AbstractDb|null $resource
*
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
public function __construct(
EntityFactoryInterface $entityFactory,
LoggerInterface $logger,
FetchStrategyInterface $fetchStrategy,
ManagerInterface $eventManager,
StoreManagerInterface $storeManager,
EntityManager\MetadataPool $metadataPool,
$mainTable,
$eventPrefix,
$eventObject,
$resourceModel,
$model = 'Magento\Framework\View\Element\UiComponent\DataProvider\Document',
$connection = null,
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);
}
/**
* @return AggregationInterface
*/
public function getAggregations()
{
return $this->aggregations;
}
/**
* @param AggregationInterface $aggregations
* @return $this
*/
public function setAggregations($aggregations)
{
$this->aggregations = $aggregations;
}
/**
* Get search criteria.
*
* @return \Magento\Framework\Api\SearchCriteriaInterface|null
*/
public function getSearchCriteria()
{
return null;
}
/**
* Set search criteria.
*
* @param \Magento\Framework\Api\SearchCriteriaInterface $searchCriteria
* @return $this
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function setSearchCriteria(\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria = null)
{
return $this;
}
/**
* Get total count.
*
* @return int
*/
public function getTotalCount()
{
return $this->getSize();
}
/**
* Set total count.
*
* @param int $totalCount
* @return $this
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function setTotalCount($totalCount)
{
return $this;
}
/**
* Set items list.
*
* @param \Magento\Framework\Api\ExtensibleDataInterface[] $items
* @return $this
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function setItems(array $items = null)
{
return $this;
}
}
My di.xml is as followed:
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Magento\Framework\View\Element\UiComponent\DataProvider\CollectionFactory">
<arguments>
<argument name="collections" xsi:type="array">
<item name="store_listing_data_source" xsi:type="string">Wavelabs\StoreLocator\Model\ResourceModel\Store\Grid\Collection</item>
</argument>
</arguments>
</type>
<type name="Wavelabs\StoreLocator\Model\ResourceModel\Store\Grid\Collection">
<arguments>
<argument name="mainTable" xsi:type="string">wavelabs_storelocator_stores</argument>
<argument name="eventPrefix" xsi:type="string">store_grid_collection</argument>
<argument name="eventObject" xsi:type="string">store_grid_collection</argument>
<argument name="resourceModel" xsi:type="string">Wavelabs\StoreLocator\Model\ResourceModel\Store</argument>
</arguments>
</type>
<virtualType name="storeGirdFilterPool" type="Magento\Framework\View\Element\UiComponent\DataProvider\FilterPool">
<arguments>
<argument name="appliers" xsi:type="array">
<item name="regular" xsi:type="object">Magento\Framework\View\Element\UiComponent\DataProvider\RegularFilter</item>
<item name="fulltext" xsi:type="object">Magento\Framework\View\Element\UiComponent\DataProvider\FulltextFilter</item>
</argument>
</arguments>
</virtualType>
<virtualType name="storeGridDataProvider" type="Magento\Framework\View\Element\UiComponent\DataProvider\DataProvider">
<arguments>
<argument name="collection" xsi:type="object" shared="false">Wavelabs\StoreLocator\Model\ResourceModel\Store\Collection</argument>
<argument name="filterPool" xsi:type="object" shared="false">storeGirdFilterPool</argument>
</arguments>
</virtualType>
</config>
I'm not 100% sure which files I need to include here. So if anyone need more information, please ask me :D
ResourceModel/Store.php
namespace Wavelabs\StoreLocator\Model\ResourceModel;
use \Magento\Framework\Model\ResourceModel\Db\AbstractDb;
class Store extends AbstractDb
{
protected function _construct()
{
$this->_init('wavelabs_storelocator_store', 'store_id');
}
}
ResourceModel/Store/Collection.php
namespace Wavelabs\StoreLocator\Model\ResourceModel\Store;
use Wavelabs\StoreLocator\Model\ResourceModel\AbstractCollection;
class Collection extends AbstractCollection
{
/**
* @var string
*/
protected $_idFieldName = 'store_id';
/**
* Load data for preview flag
*
* @var bool
*/
protected $_previewFlag;
/**
* Define resource model
*
* @return void
*/
protected function _construct()
{
$this->_init('Wavelabs\StoreLocator\Model\Store', 'Wavelabs\StoreLocator\Model\ResourceModel\HelloWorld');
}
public function setFirstStoreFlag($flag = false)
{
$this->_previewFlag = $flag;
return $this;
}
/**
* Add filter by store
*
* @param int|array|\Magento\Store\Model\Store $store
* @param bool $withAdmin
* @return $this
*/
public function addStoreFilter($store, $withAdmin = true)
{
return $this;
}
/**
* Perform operations after collection load
*
* @return $this
*/
protected function _afterLoad()
{
return parent::_afterLoad();
}
/**
* Perform operations before rendering filters
*
* @return void
*/
protected function _renderFiltersBefore()
{
return parent::_renderFiltersBefore();
}
}
Model/Store.php
namespace Wavelabs\StoreLocator\Model;
use \Magento\Framework\Model\AbstractModel;
class Store extends AbstractModel
{
protected function _construct()
{
$this->_init('Wavelabs\StoreLocator\Model\ResourceModel\Store');
}
}
Collection.php
?Collection
class}
.