Issue Bug Closed

#110814Non-admin users cannot remove file references in sys_file_metadata fields (delete button missing)

Jan Amedick 09/28/26, 11:56 updated 10/19/26, 20:44

Description

Related to #77487

Description

If a custom type => 'file' field is added to sys_file_metadata, non-admin editors can add a file reference, but they cannot remove it afterwards. The delete button is not rendered. Admins are not affected.

The DataHandler is fine with it: if the delete command is sent the same way as the form sends it (cmd[sys_file_reference][<uid>][delete]=1 plus the parent field without that uid), a non-admin user can delete the reference without errors. Only FormEngine hides the button.

Steps to reproduce

  1. Add a file field to sys_file_metadata, e.g. in Configuration/TCA/Overrides/sys_file_metadata.php:
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTCAcolumns('sys_file_metadata', [
    'preview' => [
        'label' => 'Preview',
        'config' => ['type' => 'file', 'allowed' => 'common-image-types', 'maxitems' => 1],
    ],
]);
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addToAllTCAtypes('sys_file_metadata', 'preview');
  1. Log in as a non-admin editor with tables_modify on sys_file_metadata and sys_file_reference and a file mount.
  2. Edit a file’s metadata and add an image to the field, then save. This works.
  3. Reopen the record. The file reference shows no delete button.

Expected: The editor can remove the reference, like in any other file field.

Cause

FileReferenceContainer::renderFileReferenceHeaderControl() renders the delete control only if the user may edit content on the parent record’s page:

$calcPerms = new Permission(
    $backendUser->calcPerms(BackendUtility::readPageAccess(
        (int)($this->data['parentPageRow']['uid'] ?? 0),
        $backendUser->getPagePermsClause(Permission::PAGE_SHOW)
    ))
);
// ...
if ($event->isControlEnabled('delete') && $calcPerms->editContentPermissionIsGranted()) {

sys_file_metadata records always have pid = 0. BackendUtility::readPageAccess(0, ...) returns false for non-admin users, so calcPerms() returns Permission::NOTHING, and the check always fails. ModifyFileReferenceEnabledControlsEvent cannot work around this, because the permission check is applied in addition to the event result.

Possible solution

If the parent record is on the root level (pid = 0) and its table allows root-level records (like sys_file_metadata), check table permissions instead of page permissions, e.g. $backendUser->check('tables_modify', 'sys_file_reference'). That matches what the DataHandler already allows.

Reviews 0

No change resolves or names this issue in its commit message, and no comment links one.

History 3

  1. Oliver Bartsch commented and changed status New Closed <span data-processor="relativetime" data-value="2026-10-19T20:44:59+00:00" > 10/19/26, 20:44 </span>

    Hey,

    Thanks for the detailed analysis, it matches the code in main.

    In FileReferenceContainer::renderFileReferenceHeaderControl() the delete control depends on calcPerms() of the parent page. For sys_file_metadata (rootLevel = 1) that page id is 0. For non-admins BackendUtility::readPageAccess(0, ...) returns false, so calcPerms() gives Permission::NOTHING and the button is never rendered. DataHandler allows the deletion, because sys_file_metadata / sys_file_reference set security.ignoreRootLevelRestriction.

    This is the same problem as #99516, which is still open and has a patch under review. I’m closing this issue as a duplicate so the discussion stays in one place.

    Cheers, Oli