Skip to content

Instantly share code, notes, and snippets.

@steffenk
Created September 14, 2018 06:50
Show Gist options
  • Save steffenk/8c29d1cffbff5e761cabda211a90781e to your computer and use it in GitHub Desktop.
Save steffenk/8c29d1cffbff5e761cabda211a90781e to your computer and use it in GitHub Desktop.
/**
* Build relations for FAL
*
* @param int $newStorageUid //The UID of the model
* @param array $file //The file model of the image
* @param string $field //the name of the relation field
* @param string $table //the table of the model
*/
public function buildRelations($newStorageUid, $file, $field, $table)
{
$data = [];
$data['sys_file_reference']['NEW1234'] = [
'uid_local' => $file->getUid(),
'uid_foreign' => $newStorageUid, // uid of your content record or own model
'tablenames' => $table, //tca table name
'fieldname' => $field, //see tca for fieldname
'pid' => $this->storagePid,
'table_local' => 'sys_file',
];
$data[$table][$newStorageUid] = [$field => 'NEW1234'];
/** @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, []);
$tce->process_datamap();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment