[TYPO3-dev] How to create pages/elements via Extension/Hook?

Stefan Franke stefan.franke at gmx.co.uk
Fri Aug 24 09:34:22 CEST 2018


Hello,

I need to create pages/elements on the fly when saving a page record in the backend. Right now, I'm using the following code with the hook `processDatamap_preProcessFieldArray`:

----------------------------------------------------------------code starts---
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable('pages')->createQueryBuilder();
$queryBuilder
	->insert('pages')
	->values([
		'pid' => $id,
		'title' => 'Subpage',
		'doktype' => 1,
		'urltype' => 1,
		'perms_userid' => 1,
		'perms_groupid' => 1,
		'perms_user' => 31,
		'perms_group' => 27,
		'crdate' => time(),
		'tstamp' => time(),
	])
	->execute();
------------------------------------------------------------------code ends---

This actually works, but I'd rather not work directly on the database. So I was wondering if there is a correct TYPO3-way of creating pages/content elements via extension/hook/etc.? I couldn't find a model for page or content element anywhere.

Regards,
Stefan



More information about the TYPO3-dev mailing list