#110814Non-admin users cannot remove file references in sys_file_metadata fields (delete button missing)
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
- Add a file field to
sys_file_metadata, e.g. inConfiguration/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');
- Log in as a non-admin editor with
tables_modifyonsys_file_metadataandsys_file_referenceand a file mount. - Edit a file’s metadata and add an image to the field, then save. This works.
- 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.
Related issues 1
History 3
-
Jan Amedick changed Related to #77487 <span data-processor="relativetime" data-value="2026-09-28T11:57:10+00:00" > 09/28/26, 11:57 </span>
-
Anton Danilov changed Duplicates #99516 <span data-processor="relativetime" data-value="2026-09-28T18:26:14+00:00" > 09/28/26, 18:26 </span>
-
Oliver Bartsch commented and changed status
NewClosed <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 oncalcPerms()of the parent page. Forsys_file_metadata(rootLevel = 1) that page id is 0. For non-adminsBackendUtility::readPageAccess(0, ...)returns false, socalcPerms()givesPermission::NOTHINGand the button is never rendered. DataHandler allows the deletion, becausesys_file_metadata/sys_file_referencesetsecurity.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