Feature: #99118 - PSR-14 event to define whether files are selectable¶
See forge#99118
Description¶
A new PSR-14 event \TYPO3\CMS\Backend\ElementBrowser\Event\IsFileSelectableEvent
has been introduced. It allows to define whether a file can be selected in the
file browser. Previously, this was only possible by overriding the
\TYPO3\CMS\Backend\ElementBrowser\FileBrowser->fileIsSelectableInFileList()
method via an XCLASS.
The event features the following methods:
getFile()
: Returns the\TYPO3\CMS\Core\Resource\FileInterface
in questionisFileSelectable()
: Whether the file is allowed to be selectedallowFileSelection()
: Allow selection of the file in questiondenyFileSelection()
: Deny selection of the file in question
Note
The fileIsSelectableInFileList()
method allowed to access the image
dimensions (width
and height
) via the second parameter $imgInfo
.
Those information however can be retrieved directly from the FileInterface
in a more convenient way using the getProperty()
method. Therefore,
the new Event does not provide this parameter explicitly.
Registration of the event in your extension's Services.yaml
:
MyVendor\MyExtension\Backend\MyEventListener:
tags:
- name: event.listener
identifier: 'my-extension/backend/modify-file-is-selectable'
The corresponding event listener class:
namespace MyVendor\MyExtension\Backend;
use TYPO3\CMS\Backend\ElementBrowser\Event\IsFileSelectableEvent;
final class MyEventListener {
public function __invoke(IsFileSelectableEvent $event): void
{
// Deny selection of "png" images
if ($event->getFile()->getExtension() === 'png') {
$event->denyFileSelection();
}
}
}
Impact¶
It is now possible to decide whether a file can be selected in the file browser, using an improved PSR-14 approach instead of cross classing.