1

I'm just trying to extend the sys_file_reference table with a new textfield "copyright" just the normal extbase way. Worked like a charm, field shows up. But when I save a record with a sys_file_reference relation, it won't add the reference. It's just empty after saving... It doesn't matter if the record is a page with the regular media field or if it is one of my custom extension. Anyone got an idea what I am missing?

Thanks a lot for any help!

TCA:

$fileReferenceColumns = [
'copyright' => [
    'exclude' => true,
    'label' => $ll . 'sys_file_reference.copyright',
    'config' => [
        'type' => 'input',
        'size' => 20,
        'max' => 255,
        'eval' => 'null',
        'default' => null,
    ]
]];

\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTCAcolumns('sys_file_reference', $fileReferenceColumns);
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addFieldsToPalette(
    'sys_file_reference',
    'imageoverlayPalette',
    'copyright'
);

SQL:

CREATE TABLE sys_file_reference (
  copyright VARCHAR(255) DEFAULT ''          NOT NULL,
);

Model:

class FileReference extends AbstractEntity
{

    /**
     * uid of a sys_file
     *
     * @var integer
     */
    protected $originalFileIdentifier;

    /**
     * @var \TYPO3\CMS\Extbase\Domain\Model\File
     */
    protected $file;

    /**
     * @var string
     */
    protected $copyright;

    /**
     * setOriginalResource
     *
     * @param \TYPO3\CMS\Core\Resource\FileReference $originalResource
     * @return void
     */
    public function setOriginalResource(\TYPO3\CMS\Core\Resource\FileReference $originalResource)
    {
        $this->originalResource = $originalResource;
        $this->originalFileIdentifier = (int)$originalResource->getOriginalFile()->getUid();
    }

    /**
     * @return \TYPO3\CMS\Extbase\Domain\Model\File
     */
    public function getFile()
    {
        return $this->file;
    }

    /**
     * @param \TYPO3\CMS\Extbase\Domain\Model\File $file
     */
    public function setFile($file)
    {
        $this->file = $file;
        $this->originalFileIdentifier = $file->getUid();
    }

    /**
     * @return string
     */
    public function getCopyright()
    {
        return $this->copyright;
    }

    /**
     * @param string $copyright
     */
    public function setCopyright($copyright)
    {
        $this->copyright = $copyright;
    }
}

TypoScript:

config.tx_extbase {
    persistence {
        classes {
            Interlutions\ItlGallery\Domain\Model\FileReference {
                mapping {
                    tableName = sys_file_reference
                    columns {
                        uid_local.mapOnProperty = originalFileIdentifier
                        uid_local.mapOnProperty = file
                        votes.mapOnProperty = votes
                    }
                }
            }
        }

        objects {
            TYPO3\CMS\Extbase\Domain\Model\FileReference.className = Interlutions\ItlGallery\Domain\Model\FileReference
        }
    }
}
Alex S.
  • 66
  • 8

2 Answers2

2

The problem was, that if the new field "copyright" wasn't filled out, it tried to save the value as NULL. But NULL was not allowed by SQL definition.

So changing the SQL definition to for example the following worked (looked at the field definition of sys_file_reference title and description):

CREATE TABLE sys_file_reference (
  copyright TINYTEXT,
);

I knew it was something really simple...

Alex S.
  • 66
  • 8
0

Hey and welcome to Stackoverflow :-) I guess all your references get lost because you completely "replace" the original FileReference object using:

config.tx_extbase.objects.TYPO3\CMS\Extbase\Domain\Model\FileReference.className = Interlutions\ItlGallery\Domain\Model\FileReference

In your whole system Extbase FileReference will be replaced with your FileReference. Because of this, I think important informations about every FileReference won't be stored to DB because your "override"-model is missing alot of Setters / Getters because your model only extends the AbstractEntity.

Please try to extend the existing FileReference - this will maybe solve the problem:

class FileReference extends \TYPO3\CMS\Extbase\Domain\Model\FileReference

Please notice that overriding classes using config.tx_extbase.objects may cause other extensions to break. You may consider just overriding it for your extension using plugin.tx_yourextension.objects. Your new field is anyway accessible for the default FileReference by using file.properties.copyright for example in Fluid templates.

Another thing: Because of your need of a copyright field this extension does the same: https://typo3.org/extensions/repository/view/tgm_copyright

Paul Beck
  • 2,675
  • 1
  • 12
  • 14
  • Many thanks for your hints but unfortunately both wont help. The model extends now the Extbase FileReference model and the TypoScript object mapping is changed to plugin.tx_itlgallery... The reference still get lost, either in pages or a custom model. – Alex S. May 31 '17 at 07:09
  • In pages you mean the default media field of pages or did you add your own field to pages? – Paul Beck May 31 '17 at 08:26
  • The default media field, which shouldn't be affected of my changes as the typoscript mapping is restricted to my extension now, right? – Alex S. May 31 '17 at 08:29
  • Yes if you cleared all caches in the installtool after changing the Typoscript or reinstalled your extension. – Paul Beck May 31 '17 at 10:50
  • Cleared all caches. Finally found the solution in the SQL definition. See my answer above. But many thanks for your help! – Alex S. May 31 '17 at 12:28