Feature: #99118 - PSR-14 event to define whether files are selectable
See forge#99118
Description
A new PSR-14 event \TYPO3\
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\
method via an XCLASS.
The event features the following methods:
get
: Returns theFile () \TYPO3\
in questionCMS\ Core\ Resource\ File Interface is
: Whether the file is allowed to be selectedFile Selectable () allow
: Allow selection of the file in questionFile Selection () deny
: Deny selection of the file in questionFile Selection ()
Note
The file
method allowed to access the image
dimensions (width
and height
) via the second parameter $img
.
Those information however can be retrieved directly from the File
in a more convenient way using the get
method. Therefore,
the new Event does not provide this parameter explicitly.
Registration of the event in your extension's Services.
:
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.