Custom file processors
For custom needs in terms of file processing, registration of custom file processors is available.
Create a new processor class
The file must implement the
\TYPO3\ and two required methods.
canProcess Task () - Will decide whether the given file should be handled at all. The expected return type is boolean.
processTask () - Will then do whatever needs to be done to process the given file.
Register the file processor
To register a new processor, add the following code to ext_localconf.php
<?php
$GLOBALS['TYPO3_CONF_VARS']['SYS']['fal']['processors']['MyNewImageProcessor'] = [
'className' => \MyVendor\MyExtension\Resource\Processing\MyNewImageProcessor::class,
'before' => ['LocalImageProcessor'],
];
With the before and after options, priority can be defined.
Note
Only one file processor will handle any given file. Once the first match for
can has been found, this is the
processor that will handle the file. There is no cascading or sequence possible, so make sure your processor does all the work
necessary.
Processing system resources from EXT: and PKG:
Changed in version 15.0 Breaking: #110702 - Widened FAL processing task interfaces
The processing pipeline also processes system resources. Before, an image from an extension was processed through a FAL compatibility storage.
The processing pipeline also scales and crops images that an extension or a
package ships, referenced as EXT: or PKG: system resource. For such a task
Task
returns a
System
that is not a FAL
File
. The result is
not stored in the database or in a _processed_/ folder. See
Processed files.
A processor receives such a task only if it implements the marker interface
Resource.
The Core processors
Local and
Svg
implement it for the task type Image.. A subclass of these
processors inherits the interface. If the subclass uses methods that only a FAL
file has, it must decline other sources in
can.
Example: Process only FAL files in a subclass of LocalImageProcessor
The processor declines a task if the source is not a FAL file. The Core processors then handle the system resources.
<?php
declare(strict_types=1);
namespace MyVendor\MyExtension\Resource\Processing;
use TYPO3\CMS\Core\Resource\File;
use TYPO3\CMS\Core\Resource\Processing\LocalImageProcessor;
use TYPO3\CMS\Core\Resource\Processing\TaskInterface;
class FalOnlyImageProcessor extends LocalImageProcessor
{
public function canProcessTask(TaskInterface $task): bool
{
// Leave system resources from EXT: and PKG: to the Core processors
return $task->getSourceFile() instanceof File
&& parent::canProcessTask($task);
}
}