In older TYPO3 Versions like TYPO3 8.7.x, I used DataMapper to map the results from my querybuilder select result to an array of objects. That is working fine in TYPO3 8.7.x, but in TYPO3 9.5.x, I’ve got the error message “Call to a member function buildDataMap() on null“.
//MyRepository.php namespace VendorMyExtensionDomainRepository; use TYPO3CMSCoreDatabaseConnectionPool; use TYPO3CMSCoreUtilityGeneralUtility; use TYPO3CMSExtbasePersistenceGenericMapperDataMapper; /** * @param string $search * * @return array */ public function findBySearch($search) { $querybuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('tx_myextension_domain_model_produkt'); $records = $querybuilder->select('tx_myextension_domain_model_produkt.*') ->from('tx_myextension_domain_model_produkt') ->orWhere( $querybuilder->expr()->like('titel', $querybuilder->createNamedParameter('%' . $search . '%')), $querybuilder->expr()->like('untertitel', $querybuilder->createNamedParameter('%' . $search . '%')) ) ->orderBy('titel') ->execute() ->fetchAll(); $dataMapper = GeneralUtility::makeInstance(DataMapper::class); return $dataMapper->map($this->objectType, $records); }
Advertisement
Answer
Some classes require other objects as dependencies. This is the case in TYPO3 if the properties are annotated with @inject
or if there is a matching injectPropertyName
method.
In that case, you should instantiate the class (DataMapper in this case) using the ObjectManager.
That usually looks like this:
$dataMapper = GeneralUtiity::makeInstance(ObjectManager::class)->get(DataMapper::class);