I am trying to override the Resource model for the cms page file in the sitemap module
my code is
<?php
namespace MyModuleSiteMapModelResourceModelCms;
use MagentoCmsApiDataPageInterface;
use MagentoCmsApiGetUtilityPageIdentifiersInterface;
use MagentoCmsModelPage as CmsPage;
use MagentoFrameworkAppObjectManager;
use MagentoFrameworkDBSelect;
use MagentoFrameworkEntityManagerEntityManager;
use MagentoFrameworkEntityManagerMetadataPool;
use MagentoFrameworkModelAbstractModel;
use MagentoFrameworkModelResourceModelDbAbstractDb;
use MagentoFrameworkModelResourceModelDbContext;
/**
* Sitemap cms page collection model
*
* @api
* @since 100.0.2
*/
class Page extends MagentoSitemapModelResourceModelCmsPage
{
/**
* @var MetadataPool
* @since 100.1.0
*/
protected $metadataPool;
/**
* @var EntityManager
* @since 100.1.0
*/
protected $entityManager;
/**
* @var GetUtilityPageIdentifiersInterface
*/
private $getUtilityPageIdentifiers;
/**
* @param Context $context
* @param MetadataPool $metadataPool
* @param EntityManager $entityManager
* @param string $connectionName
* @param GetUtilityPageIdentifiersInterface $getUtilityPageIdentifiers
*/
public function __construct(
Context $context,
MetadataPool $metadataPool,
EntityManager $entityManager,
$connectionName = null,
GetUtilityPageIdentifiersInterface $getUtilityPageIdentifiers = null
) {
$this->metadataPool = $metadataPool;
$this->entityManager = $entityManager;
$this->getUtilityPageIdentifiers = $getUtilityPageIdentifiers ?:
ObjectManager::getInstance()->get(GetUtilityPageIdentifiersInterface::class);
parent::__construct($context,$connectionName);
}
/**
* Retrieve cms page collection array
*
* @param int $storeId
* @return array
*/
public function getCollection($storeId)
{
$entityMetadata = $this->metadataPool->getMetadata(PageInterface::class);
$linkField = $entityMetadata->getLinkField();
$select = $this->getConnection()->select()->from(
['main_table' => $this->getMainTable()],
[$this->getIdFieldName(), 'url' => 'identifier', 'updated_at' => 'update_time', 'title' => 'title',]
)->join(
['store_table' => $this->getTable('cms_page_store')],
"main_table.{$linkField} = store_table.$linkField",
[]
)->where(
'main_table.is_active = 1'
)->where(
'main_table.identifier NOT IN (?)',
$this->getUtilityPageIdentifiers->execute()
)->where(
'store_table.store_id IN(?)',
[0, $storeId]
);
$pages = [];
$query = $this->getConnection()->query($select);
while ($row = $query->fetch()) {
$page = $this->_prepareObject($row);
$pages[$page->getId()] = $page;
}
return $pages;
}
/**
* Prepare page object
*
* @param array $data
* @return MagentoFrameworkDataObject
*/
protected function _prepareObject(array $data)
{
$object = new MagentoFrameworkDataObject();
$object->setId($data[$this->getIdFieldName()]);
$object->setUrl($data['url']);
$object->setUpdatedAt($data['updated_at']);
$object->setTitle($data['title']);
return $object;
}
}
but when I run setup:di:compile it throws an error as below:
bin/magento setup:di:compile
Compilation was started.
Interception cache generation... 6/9 [==================>---------] 66% 3 mins 558.0 MiBErrors during compilation:
MyModuleSiteMapModelResourceModelCmsPage
Incompatible argument type: Required type: MagentoFrameworkEntityManagerEntityManager. Actual type: string; File:
/var/www/html/wp11243/app/code/Calculus/SiteMap/Model/ResourceModel/Cms/Page.php
Total Errors Count: 1
In Log.php line 92:
Error during compilation
Does anyone know how to fix this?