[TYPO3-dev] Typo3 7.2 add file reference to extension model

Johannes Mueller j.f.mueller at gmx.de
Mon Jul 20 16:19:48 CEST 2015


Hey,

I try to solve the common use case of adding a file as filereference
programmatically to an extension model. I wrote an in-depth stackoverflow
article about that topic.
http://stackoverflow.com/questions/31518799/typo3-7-2-add-file-reference-to-extension-model

I'm able to fulfill my requirements via
a) Hacking core
b) Use the following code from http://wiki.typo3.org/File_Abstraction_Layer

$data = array();$data['sys_file_reference']['NEW1234'] = array(
	'uid_local' => $file->getUid(),
	'uid_foreign' => $tt_content_uid, // uid of your content record
	'tablenames' => 'tt_content',
	'fieldname' => 'image',
	'pid' => $pages_uid, // parent id of the parent page
	'table_local' => 'sys_file',);$data['tt_content'][$tt_content_uid] =
array('image' => 'NEW1234'); // set to the number of images?
 /** @var \TYPO3\CMS\Core\DataHandling\DataHandler $tce */$tce =
\TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\CMS\Core\DataHandling\DataHandler');
// create TCE instance$tce->start($data, array(), $new_BE_USER);					
$tce->process_datamap();

I think neither of these methods are the correct way to achieve this.

Thanks for infos of all kind.

-- 
Johannes Müller
Informatiker (B. Sc.)
mail: j.f.mueller at gmx.de
tel: +49 177 557 45 45
fax: +49 89 552 686 43



More information about the TYPO3-dev mailing list