typo3extbasefal

TYPO3: Extend FAL sys_file_reference with a new textfield


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

Solution

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