IsFileSelectableEvent

New in version 12.1

The PSR-14 event \TYPO3\CMS\Backend\ElementBrowser\Event\IsFileSelectableEvent allows to decide whether a file can be selected in the file browser.

To get the image dimensions (width and height) of a file, you can retrieve the file and use the getProperty() method.

Example

Registration of the event listener in the extension's Services.yaml:

EXT:my_extension/Configuration/Services.yaml
services:
  # Place here the default dependency injection configuration

  MyVendor\MyExtension\Backend\EventListener\MyEventListener:
    tags:
      - name: event.listener
        identifier: 'my-extension/backend/modify-file-is-selectable'
Copied!

Read how to configure dependency injection in extensions.

The corresponding event listener class:

EXT:my_extension/Classes/Backend/EventListener/MyEventListener.php
<?php

declare(strict_types=1);

namespace MyVendor\MyExtension\Backend\EventListener;

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();
        }
    }
}
Copied!

API

class IsFileSelectableEvent
Fully qualified name
\TYPO3\CMS\Backend\ElementBrowser\Event\IsFileSelectableEvent

Listeners to this event are able to define whether a file can be selected in the file browser

getFile ( )
Returns
TYPO3CMSCoreResourceFileInterface
isFileSelectable ( )
Returns
bool
allowFileSelection ( )
denyFileSelection ( )