http://forge.typo3.org/http://forge.typo3.org/themes/typo3_forge/favicon/favicon.png?17058661692013-11-30T17:02:00ZTYPO3 ForgeTYPO3 Core - Bug #48965: FileReference can't be created in Frontend contexthttp://forge.typo3.org/issues/48965?journal_id=1922302013-11-30T17:02:00ZSteffen Ritterinfo@rs-websystems.de
<ul><li><strong>Target version</strong> deleted (<del><i>6.2.0</i></del>)</li></ul> TYPO3 Core - Bug #48965: FileReference can't be created in Frontend contexthttp://forge.typo3.org/issues/48965?journal_id=2124832014-04-09T16:56:45ZFrank Näglerfrank.naegler@typo3.org
<ul></ul><p>this is also a problem within a command controller.</p> TYPO3 Core - Bug #48965: FileReference can't be created in Frontend contexthttp://forge.typo3.org/issues/48965?journal_id=2124862014-04-09T17:03:58ZMathias Brodalambrodala@pagemachine.de
<ul><li><strong>Target version</strong> set to <i>next-patchlevel</i></li></ul> TYPO3 Core - Bug #48965: FileReference can't be created in Frontend contexthttp://forge.typo3.org/issues/48965?journal_id=2160802014-05-08T21:09:07ZFrans Sarisfranssaris@gmail.com
<ul><li><strong>Is Regression</strong> set to <i>No</i></li></ul><p>The only thing what currently is missing for this is:</p>
<pre>
/**
* Class FileReference
*/
class FileReference extends \TYPO3\CMS\Extbase\Domain\Model\FileReference {
/**
* We need this property so that the Extbase persistence can properly persist the object
*
* @var integer
*/
protected $uidLocal;
/**
* @param \TYPO3\CMS\Core\Resource\FileReference $originalResource
*/
public function setOriginalResource(\TYPO3\CMS\Core\Resource\FileReference $originalResource) {
$this->originalResource = $originalResource;
$this->uidLocal = $originalResource->getOriginalFile()->getUid();
}
}
</pre>
<p>When setting the foreign_match_fields in TCA and using a model that has the above modifications your able to persist a sys_file_reference</p>
<p>Have a look at Helmut's approuch here <a class="external" href="https://github.com/helhum/upload_example">https://github.com/helhum/upload_example</a></p> TYPO3 Core - Bug #48965: FileReference can't be created in Frontend contexthttp://forge.typo3.org/issues/48965?journal_id=2163282014-05-11T16:03:32ZSimon no-lastname-givensm@milzer.de
<ul><li><strong>File</strong> <a href="/attachments/26674">Screenshot_2014-05-11_16.02.22.jpg</a> <a class="icon-only icon-download" title="Download" href="/attachments/download/26674/Screenshot_2014-05-11_16.02.22.jpg">Screenshot_2014-05-11_16.02.22.jpg</a> added</li></ul><p>i got the same error within a command controller:</p>
<pre>
$fileIdentifier = 'example.jpg';
$storage = $storageRepository->findByUid(1);
$file = $storage->getFile($fileIdentifier);
$fileReference = $this->objectManager->get('TYPO3\\CMS\\Extbase\\Domain\\Model\\FileReference');
$fileReference->setOriginalResource($file);
$model->addImage($fileReference);
</pre>
<p>attached a screenshot with the sys_file_reference table.</p> TYPO3 Core - Bug #48965: FileReference can't be created in Frontend contexthttp://forge.typo3.org/issues/48965?journal_id=2164202014-05-12T11:08:11ZFrans Sarisfranssaris@gmail.com
<ul></ul><p>Hi Simon,</p>
<p>You need to use your own FileReference object that implements setOriginalResource() like described above.</p>
<pre>
$fileReference = $this->objectManager->get('MyVendor\\MyExtension\\Domain\\Model\\FileReference');
$fileReference->setOriginalResource($file);
</pre>
<p>And can you post the TCA here. Maybe we can spot the error.</p>
<p>gr. Frans</p> TYPO3 Core - Bug #48965: FileReference can't be created in Frontend contexthttp://forge.typo3.org/issues/48965?journal_id=2233572014-07-08T13:24:37ZLars Alars.albrecht+typo3@googlemail.com
<ul></ul><p>I have also an empty File Reference in the database :/<br />File is filled<br />File Reference has only a filled uid_local (also uid, tstamp and crdate).</p>
<p>My TCA is like the one of Helmuts example.</p>
<p>My only differents is, that i use 6.1(.8)</p> TYPO3 Core - Bug #48965: FileReference can't be created in Frontend contexthttp://forge.typo3.org/issues/48965?journal_id=2234532014-07-09T08:53:47ZFrans Sarisfranssaris@gmail.com
<ul></ul><p>You need at least 6.2 to get this to work.</p> TYPO3 Core - Bug #48965: FileReference can't be created in Frontend contexthttp://forge.typo3.org/issues/48965?journal_id=2240092014-07-12T12:39:36ZDaniel Ostmanndos@pixelbrand.net
<ul></ul><p>Thank you Frans, for me it works perfectly with an own FileReference.</p>
<p>Take a look into <a class="external" href="https://github.com/helhum/upload_example">https://github.com/helhum/upload_example</a>!</p>
<p>Just define in your own FileReference a property uidLocal. That's it.</p>
<pre>
class FileReference extends \TYPO3\CMS\Extbase\Domain\Model\FileReference {
/**
* We need this property so that the Extbase persistence can properly persist the object
*
* @var integer
*/
protected $uidLocal;
/**
* @param \TYPO3\CMS\Core\Resource\FileReference $originalResource
*/
public function setOriginalResource(\TYPO3\CMS\Core\Resource\FileReference $originalResource) {
$this->originalResource = $originalResource;
$this->uidLocal = $originalResource->getOriginalFile()->getUid();
}
}
</pre> TYPO3 Core - Bug #48965: FileReference can't be created in Frontend contexthttp://forge.typo3.org/issues/48965?journal_id=2345672014-10-31T11:53:34ZJan Kornblumjan.kornblum@googlemail.com
<ul></ul><p>What am i doing wrong? I've used an own FileReference object extended as described above and mapped it to sys_file_reference. But i get the following error:</p>
<pre>
#1: PHP Catchable Fatal Error: Argument 1 passed to XXX\YYY\Domain\Model\FileReference::setOriginalResource() must be an instance of TYPO3\CMS\Core\Resource\FileReference, instance of TYPO3\CMS\Core\Resource\File given, called in /zzz/AnyController.php...
</pre> TYPO3 Core - Bug #48965: FileReference can't be created in Frontend contexthttp://forge.typo3.org/issues/48965?journal_id=2353622014-11-06T14:42:20ZThomas Christiansenthomas@flense.de
<ul></ul><p>Today i ran into the same problem and i finally got it working. Although i had to adapt your solutions a little bit.</p>
<p>This is my FileReference Model:</p>
<pre>
class FileReference extends \TYPO3\CMS\Extbase\Domain\Model\FileReference {
/**
* We need this property so that the Extbase persistence can properly persist the object
*
* @var integer
*/
protected $uidLocal;
/**
* @param \TYPO3\CMS\Core\Resource\ResourceInterface $originalResource
*/
public function setOriginalResource(\TYPO3\CMS\Core\Resource\ResourceInterface $originalResource) {
$this->originalResource = $originalResource;
$this->uidLocal = (int)$originalResource->getUid();
}
}
</pre>
<p>Note that the setter expects an object of type ResourceInterface and NOT FileReference.</p>
<p>Then i ran into an SQL Error, because the table of my extended model does of course not exist.<br />So i had to configure extbase table mapping:</p>
<pre>
plugin.tx_foo.persistence.classes.Vendor\Foo\Domain\Model\FileReference.mapping.tableName = sys_file_reference
</pre>
<p>Also make sure, that your TCA includes this config:</p>
<pre>
'foreign_match_fields' => array(
'fieldname' => 'whatever_your_field_is_called',
'tablenames' => 'tx_foo_domain_model_bar',
'table_local' => 'sys_file',
),
</pre>
<p>Summarized: Piece of cake.. No seriously, this is not pretty :/</p>
<p>Btw i am working in a CommandController..</p> TYPO3 Core - Bug #48965: FileReference can't be created in Frontend contexthttp://forge.typo3.org/issues/48965?journal_id=2353732014-11-06T15:47:18ZDaniel Ostmanndos@pixelbrand.net
<ul></ul><p>Mmh, for me it wasn't necessary to define anything in TCA. I think it depends on what you wanna do with it. For me it works perfectly by just defining the $uidLocal property in my own FileReference model and use it instead of the original FileReference.</p> TYPO3 Core - Bug #48965: FileReference can't be created in Frontend contexthttp://forge.typo3.org/issues/48965?journal_id=2353742014-11-06T15:53:15ZJan Kornblumjan.kornblum@googlemail.com
<ul></ul><p>Do you know this thread (including the examples at github):</p>
<p><a class="external" href="http://forum.typo3.org/index.php?t=msg&th=206859&goto=721954&#msg_721954">http://forum.typo3.org/index.php?t=msg&th=206859&goto=721954&#msg_721954</a></p>
<p>That worked perfectly for me!</p> TYPO3 Core - Bug #48965: FileReference can't be created in Frontend contexthttp://forge.typo3.org/issues/48965?journal_id=2353762014-11-06T16:32:11ZThomas Christiansenthomas@flense.de
<ul></ul><p>Ah ok i was not aware that there are two kinds of FileReferences as well, but basically i wrote nearly the same setFile-Function as Helmut here <a class="external" href="https://gist.github.com/helhum/9a274ac1c29b50eedd71">https://gist.github.com/helhum/9a274ac1c29b50eedd71</a><br />Although i put it in the setOriginalResource in my Model :)</p>
<p>Btw i am trying to set a FileReference to i file which i got via:<br />$storage = $storageRepository->findByUid(1);<br />$file = $storage->getFile('foo.jpg');</p>
<p><a class="user active user-mention" href="http://forge.typo3.org/users/355">@Daniel Hinderink</a>: I totally need the TCA Config, if I dont have it the columns "tablenames" and "table_local" in sys_file_reference are emtpy.</p>
<p>I was really confused about the $originalFileIdentifier property, because i didtn see the property mapping on uid_local in the typoscript.</p>
<p>So everything is working now, but i dont like the solution :)</p> TYPO3 Core - Bug #48965: FileReference can't be created in Frontend contexthttp://forge.typo3.org/issues/48965?journal_id=2514162015-03-02T17:22:22ZGerrit Code Review
<ul><li><strong>Status</strong> changed from <i>New</i> to <i>Under Review</i></li></ul><p>Patch set 3 for branch <strong>master</strong> of project <strong>Packages/TYPO3.CMS</strong> has been pushed to the review server.<br />It is available at <a class="external" href="http://review.typo3.org/37417">http://review.typo3.org/37417</a></p> TYPO3 Core - Bug #48965: FileReference can't be created in Frontend contexthttp://forge.typo3.org/issues/48965?journal_id=2514172015-03-02T17:25:11ZGerrit Code Review
<ul></ul><p>Patch set 4 for branch <strong>master</strong> of project <strong>Packages/TYPO3.CMS</strong> has been pushed to the review server.<br />It is available at <a class="external" href="http://review.typo3.org/37417">http://review.typo3.org/37417</a></p> TYPO3 Core - Bug #48965: FileReference can't be created in Frontend contexthttp://forge.typo3.org/issues/48965?journal_id=2514182015-03-02T17:29:10ZGerrit Code Review
<ul></ul><p>Patch set 5 for branch <strong>master</strong> of project <strong>Packages/TYPO3.CMS</strong> has been pushed to the review server.<br />It is available at <a class="external" href="http://review.typo3.org/37417">http://review.typo3.org/37417</a></p> TYPO3 Core - Bug #48965: FileReference can't be created in Frontend contexthttp://forge.typo3.org/issues/48965?journal_id=2514242015-03-02T17:45:16ZGerrit Code Review
<ul></ul><p>Patch set 1 for branch <strong>TYPO3_6-2</strong> of project <strong>Packages/TYPO3.CMS</strong> has been pushed to the review server.<br />It is available at <a class="external" href="http://review.typo3.org/37463">http://review.typo3.org/37463</a></p> TYPO3 Core - Bug #48965: FileReference can't be created in Frontend contexthttp://forge.typo3.org/issues/48965?journal_id=2514282015-03-02T18:00:19ZAnonymous
<ul><li><strong>Status</strong> changed from <i>Under Review</i> to <i>Resolved</i></li><li><strong>% Done</strong> changed from <i>0</i> to <i>100</i></li></ul><p>Applied in changeset <a class="changeset" title="[BUGFIX] Add property "uidLocal" to extbase FileReference model This is needed so extbase persis..." href="http://forge.typo3.org/projects/typo3cms-core/repository/1749/revisions/035f15ca16eb8e141bbf96f1c25692c25ac123ff">035f15ca16eb8e141bbf96f1c25692c25ac123ff</a>.</p> TYPO3 Core - Bug #48965: FileReference can't be created in Frontend contexthttp://forge.typo3.org/issues/48965?journal_id=3842062018-10-02T12:14:20ZBenni Mackbenni@typo3.org
<ul><li><strong>Status</strong> changed from <i>Resolved</i> to <i>Closed</i></li></ul> TYPO3 Core - Bug #48965: FileReference can't be created in Frontend contexthttp://forge.typo3.org/issues/48965?journal_id=4038382019-07-23T18:30:43ZJan Kornblumjan.kornblum@googlemail.com
<ul><li><strong>Target version</strong> deleted (<del><i>next-patchlevel</i></del>)</li><li><strong>TYPO3 Version</strong> changed from <i>6.2</i> to <i>9</i></li></ul><p>I hope this won't be reopened wrongly, but it is still missing to create a new file reference based on a given file object. So still an own FileReference class must be used. A method "setFile()" shoul be added like below...</p>
<pre><code class="php syntaxhl" data-language="php"><span class="cd">/**
* Class FileReference
*/</span>
<span class="kd">class</span> <span class="nc">FileReference</span> <span class="kd">extends</span> <span class="nc">\TYPO3\CMS\Extbase\Domain\Model\FileReference</span> <span class="p">{</span>
<span class="cd">/**
* uid of a sys_file
*
* @var integer
*/</span>
<span class="k">protected</span> <span class="nv">$originalFileIdentifier</span><span class="p">;</span>
<span class="cd">/**
* setOriginalResource
*
* @param \TYPO3\CMS\Core\Resource\ResourceInterface $originalResource
* @return void
*/</span>
<span class="k">public</span> <span class="k">function</span> <span class="n">setOriginalResource</span><span class="p">(</span><span class="nc">\TYPO3\CMS\Core\Resource\ResourceInterface</span> <span class="nv">$originalResource</span><span class="p">)</span> <span class="p">{</span>
<span class="nv">$this</span><span class="o">-></span><span class="n">originalResource</span> <span class="o">=</span> <span class="nv">$originalResource</span><span class="p">;</span>
<span class="nv">$this</span><span class="o">-></span><span class="n">originalFileIdentifier</span> <span class="o">=</span> <span class="p">(</span><span class="n">int</span><span class="p">)</span><span class="nv">$originalResource</span><span class="o">-></span><span class="nf">getOriginalFile</span><span class="p">()</span><span class="o">-></span><span class="nf">getUid</span><span class="p">();</span>
<span class="p">}</span>
<span class="cd">/**
* setFile
*
* @param \TYPO3\CMS\Core\Resource\File $falFile
* @return void
*/</span>
<span class="k">public</span> <span class="k">function</span> <span class="n">setFile</span><span class="p">(</span><span class="nc">\TYPO3\CMS\Core\Resource\File</span> <span class="nv">$falFile</span><span class="p">)</span> <span class="p">{</span>
<span class="nv">$this</span><span class="o">-></span><span class="n">originalFileIdentifier</span> <span class="o">=</span> <span class="p">(</span><span class="n">int</span><span class="p">)</span><span class="nv">$falFile</span><span class="o">-></span><span class="nf">getUid</span><span class="p">();</span>
<span class="p">}</span>
<span class="p">}</span>
</code></pre> TYPO3 Core - Bug #48965: FileReference can't be created in Frontend contexthttp://forge.typo3.org/issues/48965?journal_id=4038522019-07-24T12:18:24ZJan Kornblumjan.kornblum@googlemail.com
<ul></ul><p>New issue opened for this: <a class="external" href="https://forge.typo3.org/issues/88833">https://forge.typo3.org/issues/88833</a></p> TYPO3 Core - Bug #48965: FileReference can't be created in Frontend contexthttp://forge.typo3.org/issues/48965?journal_id=4154552020-02-16T13:24:55ZChristian Eßl
<ul><li><strong>Related to</strong> <i><a class="issue tracker-2 status-8 priority-4 priority-default" href="/issues/90374">Feature #90374</a>: Add setOriginaFile / setFile setter to TYPO3\CMS\Extbase\Domain\Model\FileReference</i> added</li></ul> TYPO3 Core - Bug #48965: FileReference can't be created in Frontend contexthttp://forge.typo3.org/issues/48965?journal_id=4348922020-11-12T09:33:37ZJan Kornblumjan.kornblum@googlemail.com
<ul><li><strong>Related to</strong> <i><a class="issue tracker-2 status-8 priority-4 priority-default" href="/issues/88833">Feature #88833</a>: Extend possibility to create FileReference in frontend with a given File object</i> added</li></ul>