typo3typo3-7.x

TYPO3 File Reference delete file and reference


How to delete the file and the file reference from this model? I mean by code in controller. As far as I know there is no method to delete files.

The according TCA:

'backgroundimage' => array(
    'label' => 'LLL:EXT:feusersplus/Resources/Private/Language/locallang_db.xlf:tx_feusersplus_domain_model_user.backgroundimage',
    'config' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getFileFieldTCAConfig(
        'image', array(
            'appearance' => array(
                'createNewRelationLinkTitle' => 'LLL:EXT:cms/locallang_ttc.xlf:images.addFileReference'
            ),
            'maxitems' => 1,
            'foreign_match_fields' => array(
                'fieldname' => 'backgroundimage',
                'tablenames' => 'fe_users',
                'table_local' => 'sys_file',
            ),
            'foreign_types' => array(
                '0' => array(
                    'showitem' => '
                        --palette--;LLL:EXT:lang/locallang_tca.xlf:sys_file_reference.imageoverlayPalette;imageoverlayPalette,
                        --palette--;;filePalette'
                ),
                \TYPO3\CMS\Core\Resource\File::FILETYPE_TEXT => array(
                    'showitem' => '
                        --palette--;LLL:EXT:lang/locallang_tca.xlf:sys_file_reference.imageoverlayPalette;imageoverlayPalette,
                        --palette--;;filePalette'
                ),
                \TYPO3\CMS\Core\Resource\File::FILETYPE_IMAGE => array(
                    'showitem' => '
                        --palette--;LLL:EXT:lang/locallang_tca.xlf:sys_file_reference.imageoverlayPalette;imageoverlayPalette,
                        --palette--;;filePalette'
                ),
                \TYPO3\CMS\Core\Resource\File::FILETYPE_AUDIO => array(
                    'showitem' => '
                        --palette--;LLL:EXT:lang/locallang_tca.xlf:sys_file_reference.imageoverlayPalette;imageoverlayPalette,
                        --palette--;;filePalette'
                ),
                \TYPO3\CMS\Core\Resource\File::FILETYPE_VIDEO => array(
                    'showitem' => '
                        --palette--;LLL:EXT:lang/locallang_tca.xlf:sys_file_reference.imageoverlayPalette;imageoverlayPalette,
                        --palette--;;filePalette'
                ),
                \TYPO3\CMS\Core\Resource\File::FILETYPE_APPLICATION => array(
                    'showitem' => '
                        --palette--;LLL:EXT:lang/locallang_tca.xlf:sys_file_reference.imageoverlayPalette;imageoverlayPalette,
                        --palette--;;filePalette'
                )
            )
        ), $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'])
    ), 
),

The according Model:

/**
  * backgroundimage
  *
  * @var \TYPO3\CMS\Extbase\Domain\Model\FileReference
*/
protected $backgroundimage = null;

I am using TYPO3 7.6.18

Thank you in advance


Solution

  • If you remove the file $file->getStorage()->deleteFile($file); the fileReference gets deleted automatically