/**
  * Creates a sys_file_reference record
  *
  * @param string $table                                  table    the file reference relates to
  * @param string $field                                  field    the file reference relates to
  * @param \TYPO3\CMS\Extbase\DomainObject\AbstractEntity $record  record the file reference relates to
  * @param \TYPO3\CMS\Core\Resource\File                  $file    file the file reference relates to
  * @return array                                                  error log if an error occurs
  */
 protected function addFileReference($table, $field, \TYPO3\CMS\Extbase\DomainObject\AbstractEntity $record, \TYPO3\CMS\Core\Resource\File $file)
 {
     // Make user admin temporarily to circumvent permission issues
     $adminStatus = $GLOBALS['BE_USER']->user['admin'];
     $GLOBALS['BE_USER']->user['admin'] = true;
     // Define content for file reference record
     $data = array();
     $data['sys_file_reference']['NEW1234'] = array('uid_local' => $file->getUid(), 'uid_foreign' => $record->getUid(), 'tablenames' => $table, 'fieldname' => $field, 'pid' => $record->getPid(), 'table_local' => 'sys_file');
     // Create relation to main record
     $data[$table][$record->getUid()] = array($field => 'NEW1234');
     // Use TYPO3 data handler to simulate form submit in backend
     $tce = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\DataHandling\\DataHandler');
     $tce->start($data, array());
     $tce->process_datamap();
     // Revert original admin status
     $GLOBALS['BE_USER']->user['admin'] = $adminStatus;
     return $tce->errorLog;
 }