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

Johannes Mueller j.f.mueller at gmx.de
Tue Jul 21 18:06:06 CEST 2015


Okay. Some small issues towards perfection:

1) The sys_file_reference table does not contain a value for table_local,
whereas all the entries generated by a backend user hold sys_file as value.
2) The same applies to l10n_diffsource which holds some binary large
object. This entry gets inserted in the sys_file_reference table after
saving the record manually via backend.
3) The pid of the file_reference has to be set via
setPid($model->getPid()), is that okay?
4) The cruser_id is always set to zero. Is this the correct way?
5) When trying to delete a file (which was added to a model with the
backend possibilities) via the file manager, I get a warning, that
references to this file exist. This does not apply to the fileReference
added programmatically. Also the references listed under the file (when
clicking on "Info" for a generated file in the backend file manager) don't
get listed. They get listed, when I enter the "sys_file" value in the
sys_file_reference table by hand.
6) As the Helmut Hummels example holds additional data, I'm wondering, if I
just miss some stuff.
7) The file reference is used inside an object storage, but as the addImage
function only calls objectStorage->attach I think this should be okay and
no additional objectStorage actions are neccessary.

Thanks in advance for any hints.

2015-07-21 12:54 GMT+02:00 Frans Saris <franssaris at gmail.com>:

> Hi Johannes,
>
> when using a own model you have to tell the extbase persistence layer what
> table to use if you want to use a already existing table.
>
> see for instance
>
> https://github.com/helhum/upload_example/blob/master/ext_typoscript_setup.txt
>
> gr. Frans
>
> Op ma 20 jul. 2015 om 16:19 schreef Johannes Mueller <j.f.mueller at gmx.de>:
>
> > 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
> > _______________________________________________
> > TYPO3-dev mailing list
> > TYPO3-dev at lists.typo3.org
> > http://lists.typo3.org/cgi-bin/mailman/listinfo/typo3-dev
> _______________________________________________
> TYPO3-dev mailing list
> TYPO3-dev at lists.typo3.org
> http://lists.typo3.org/cgi-bin/mailman/listinfo/typo3-dev




-- 
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