### Install filefill via Composer Source: https://github.com/ichhabrecht/filefill/blob/main/README.md Command to install the extension as a development dependency. ```bash composer require --dev ichhabrecht/filefill ``` -------------------------------- ### Domain Resource Handler - Fetch Files Source: https://context7.com/ichhabrecht/filefill/llms.txt Fetches missing files from a specified remote URL using the DomainResource handler. It performs a HEAD request to check existence and retrieves content when needed. Supports internal API usage for checking and getting files. ```php // Configuration for single domain resource $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['filefill']['storages'][1] = [ [ 'identifier' => 'domain', 'configuration' => 'https://www.production-site.com', ], ]; // Internal API: DomainResource implements RemoteResourceInterface use IchHabRecht\Filefill\Resource\Handler\DomainResource; $domainResource = new DomainResource('https://www.production-site.com'); // Check if file exists on remote server (performs HEAD request) $exists = $domainResource->hasFile( '/user_upload/image.jpg', // fileIdentifier 'fileadmin/user_upload/image.jpg', // filePath $fileObject // optional FileInterface ); // Returns: true if HTTP 200, false otherwise // Retrieve file content from remote server $content = $domainResource->getFile( '/user_upload/image.jpg', 'fileadmin/user_upload/image.jpg', $fileObject ); // Returns: resource stream or string content, false on failure ``` -------------------------------- ### Configure filefill via TYPO3_CONF_VARS Source: https://github.com/ichhabrecht/filefill/blob/main/README.md PHP configuration array defining the resource chain for a specific file storage UID. This allows setting up multiple fallback sources like domains, placeholders, and static file content. ```php $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['filefill']['storages'][1] = [ [ 'identifier' => 'domain', 'configuration' => 'https://example.com', ], [ 'identifier' => 'domain', 'configuration' => 'https://another-example.com', ], [ 'identifier' => 'placehold', ], [ 'identifier' => 'imagebuilder', 'configuration' => [ 'backgroundColor' => '#FFFFFF', 'textColor' => '#000000', ], ], [ 'identifier' => 'static', 'configuration' => [ 'path/to/example/file.txt' => 'Hello world!', 'another' => [ 'path' => [ 'to' => [ 'anotherFile.txt' => 'Lorem ipsum', '*.youtube' => 'yiJjpKzCVE4', ], '*' => 'This file was found in /another/path folder.', ], ], '*.vimeo' => '143018597', '*' => 'This is some static text for all other files.', ], ], ]; ``` -------------------------------- ### Configure static file resources via TypoScript Source: https://github.com/ichhabrecht/filefill/blob/main/README.md TypoScript syntax for defining static file content mapping based on paths or file extensions. ```typoscript path/to/example/file.txt = Hello world! another { path { to { anotherFile\.txt = Lorem ipsum *\.youtube => yiJjpKzCVE4 } * = This file was found in /another/path folder. } } *\.vimeo = 143018597 * = This is some static text for all other files. ``` -------------------------------- ### Configure Filefill Storage Resources Source: https://context7.com/ichhabrecht/filefill/llms.txt Configures fallback resources for TYPO3 file storages using PHP. Multiple resources form a chain processed in order until a file is found. Supports domain fetching, placeholder generation, and static content. ```php // Configure in ext_localconf.php or AdditionalConfiguration.php // Storage UID 1 configuration with multiple fallback resources $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['filefill']['storages'][1] = [ // First: Try fetching from production domain [ 'identifier' => 'domain', 'configuration' => 'https://production.example.com', ], // Second: Try fetching from staging domain [ 'identifier' => 'domain', 'configuration' => 'https://staging.example.com', ], // Third: Generate placeholder images via placehold.co [ 'identifier' => 'placehold', ], // Fourth: Generate images with ImageBuilder (shows dimensions) [ 'identifier' => 'imagebuilder', 'configuration' => [ 'backgroundColor' => '#CCCCCC', 'textColor' => '#333333', ], ], // Fifth: Provide static file content as last resort [ 'identifier' => 'static', 'configuration' => [ 'path/to/specific/file.txt' => 'Specific file content', '*.pdf' => 'PDF placeholder content', '*' => 'Default fallback content for any file', ], ], ]; ``` -------------------------------- ### Register and Implement Custom Resource Handler Source: https://context7.com/ichhabrecht/filefill/llms.txt Demonstrates how to register a custom resource handler in ext_localconf.php and implement the RemoteResourceInterface to handle remote file checks and retrieval. ```php // ext_localconf.php - Register custom resource handler $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['filefill']['resourceHandler']['myCustomResource'] = [ 'title' => 'LLL:EXT:my_extension/Resources/Private/Language/locallang.xlf:resource.title', 'handler' => \Vendor\MyExtension\Resource\Handler\MyCustomResource::class, 'config' => [ 'label' => 'API Endpoint URL', 'config' => [ 'type' => 'input', 'eval' => 'required', 'placeholder' => 'https://api.example.com/files', ], ], ]; // Classes/Resource/Handler/MyCustomResource.php namespace Vendor\MyExtension\Resource\Handler; use IchHabRecht\Filefill\Resource\RemoteResourceInterface; use TYPO3\CMS\Core\Http\RequestFactory; use TYPO3\CMS\Core\Resource\FileInterface; use TYPO3\CMS\Core\Utility\GeneralUtility; class MyCustomResource implements RemoteResourceInterface { protected string $apiEndpoint; protected RequestFactory $requestFactory; public function __construct($configuration, ?RequestFactory $requestFactory = null) { $this->apiEndpoint = rtrim((string)$configuration, '/'); $this->requestFactory = $requestFactory ?: GeneralUtility::makeInstance(RequestFactory::class); } public function hasFile($fileIdentifier, $filePath, ?FileInterface $fileObject = null): bool { try { $response = $this->requestFactory->request( $this->apiEndpoint . '/check?file=' . urlencode($filePath), 'GET', ['headers' => ['Accept' => 'application/json']] ); $data = json_decode($response->getBody()->getContents(), true); return $data['exists'] ?? false; } catch (\Exception $e) { return false; } } public function getFile($fileIdentifier, $filePath, ?FileInterface $fileObject = null) { try { $response = $this->requestFactory->request( $this->apiEndpoint . '/download?file=' . urlencode($filePath), 'GET' ); return $response->getBody()->getContents(); } catch (\Exception $e) { return false; } } } ``` -------------------------------- ### Configure Filefill Debugging and Logging Source: https://context7.com/ichhabrecht/filefill/llms.txt Enables detailed logging for file fetching operations by configuring a dedicated log writer for the filefill namespace in TYPO3. This helps in troubleshooting file fetching issues by tracing resource handling. ```php // Configuration/AdditionalConfiguration.php or ext_localconf.php $GLOBALS['TYPO3_CONF_VARS']['LOG']['IchHabRecht']['Filefill'] = [ 'writerConfiguration' => [ // Log all messages at DEBUG level and above \TYPO3\CMS\Core\Log\LogLevel::DEBUG => [ \TYPO3\CMS\Core\Log\Writer\FileWriter::class => [ 'logFileInfix' => 'filefill', // Creates: var/log/typo3_filefill_.log ], ], ], ]; // For more selective logging (only warnings and errors) $GLOBALS['TYPO3_CONF_VARS']['LOG']['IchHabRecht']['Filefill'] = [ 'writerConfiguration' => [ \TYPO3\CMS\Core\Log\LogLevel::WARNING => [ \TYPO3\CMS\Core\Log\Writer\FileWriter::class => [ 'logFileInfix' => 'filefill_errors', ], ], ], ]; ``` -------------------------------- ### Execute Filefill Cleanup via CLI Source: https://context7.com/ichhabrecht/filefill/llms.txt Commands to delete files fetched by Filefill from local storage, supporting filtering by resource identifier and storage UID. ```bash # Delete all files fetched by filefill vendor/bin/typo3 filefill:delete --all # Delete files from specific resource identifier vendor/bin/typo3 filefill:delete -i placehold # Delete files from a specific storage vendor/bin/typo3 filefill:delete -a -s 1 # Combined: specific identifier from specific storage vendor/bin/typo3 filefill:delete --identifier=domain --storage=2 ``` -------------------------------- ### Implementing a Custom Resource Handler Source: https://github.com/ichhabrecht/filefill/blob/main/README.md This snippet shows the implementation of a resource handler class that adheres to the RemoteResourceInterface. It requires the implementation of hasFile and getFile methods to manage remote file resources. ```php namespace Vendor\Extension\Resource; class ResourceHandler implements \IchHabRecht\Filefill\Resource\RemoteResourceInterface { public function hasFile($fileIdentifier, $filePath, ?FileInterface $fileObject = null) { return true; } public function getFile($fileIdentifier, $filePath, ?FileInterface $fileObject = null) { return 'file content'; } } ``` -------------------------------- ### Generate Placeholder Images with ImageBuilderResource (PHP) Source: https://context7.com/ichhabrecht/filefill/llms.txt The ImageBuilderResource handler creates placeholder images with dimensions overlayed. It requires the GD library and supports GIF, JPEG, and PNG. Configuration can be done via TYPO3_CONF_VARS, specifying background and text colors. The handler provides methods to check if an image can be generated and to generate the image content. ```php $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['filefill']['storages'][1] = [ [ 'identifier' => 'imagebuilder', 'configuration' => [ 'backgroundColor' => '#F0F0F0', 'textColor' => '#666666', ], ], ]; // Alternative: comma-separated color configuration $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['filefill']['storages'][1] = [ [ 'identifier' => 'imagebuilder', 'configuration' => 'F0F0F0, 666666', // background, text (without #) ], ]; // Supported file extensions: gif, jpeg, jpg, png // Requires GD library (class_exists(\GdImage::class)) // Internal API usage use IchHabRecht\Filefill\Resource\Handler\ImageBuilderResource; $imageBuilder = new ImageBuilderResource([ 'backgroundColor' => '#EEEEEE', 'textColor' => '#333333', ]); // Check if image can be generated $canHandle = $imageBuilder->hasFile( '/user_upload/photo.png', 'fileadmin/user_upload/photo.png', $fileObject // FileInterface with width=800, height=600 ); // Returns: true if GD available and supported extension // Generate placeholder image with dimensions overlay $imageContent = $imageBuilder->getFile( '/user_upload/photo.png', 'fileadmin/user_upload/photo.png', $fileObject ); // Returns: PNG binary with "800 x 600" text centered on colored background ``` -------------------------------- ### Provide Fallback Content with StaticFileResource (PHP) Source: https://context7.com/ichhabrecht/filefill/llms.txt The StaticFileResource handler offers fallback content for files based on path, extension, or wildcards. It can be configured via TYPO3_CONF_VARS or TypoScript. The handler's `hasFile()` method always returns true, and `getFile()` returns the configured content for the matched pattern or a global fallback. ```php $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['filefill']['storages'][1] = [ [ 'identifier' => 'static', 'configuration' => [ // Exact file path match 'path/to/specific/file.txt' => 'Exact content for this file', // Nested directory configuration 'documents' => [ 'contracts' => [ 'template.pdf' => 'Contract template content', '*.docx' => 'Default Word document placeholder', ], '*' => 'Default content for documents folder', ], // Extension-based wildcards '*.youtube' => 'dQw4w9WgXcQ', // YouTube video ID '*.vimeo' => '143018597', // Vimeo video ID '*.pdf' => 'PDF placeholder content', // Global fallback for any unmatched file '*' => 'This is placeholder content for missing files.', ], ], ]; // TypoScript syntax for database record configuration (FlexForm) /* path/to/specific/file.txt = Exact content for this file documents { contracts { template\.pdf = Contract template content *\.docx = Default Word document placeholder } * = Default content for documents folder } *\.youtube = dQw4w9WgXcQ *\.vimeo = 143018597 *\.pdf = PDF placeholder content * = This is placeholder content for missing files. */ // Internal API: StaticFileResource always returns true for hasFile() use IchHabRecht\Filefill\Resource\Handler\StaticFileResource; $staticResource = new StaticFileResource([ '*.txt' => 'Default text content', '*' => 'Fallback content', ]); $content = $staticResource->getFile( '/user_upload/readme.txt', 'fileadmin/user_upload/readme.txt', $fileObject ); // Returns: 'Default text content' (matched by *.txt) ``` -------------------------------- ### Configuring Debug Logging for Filefill Source: https://github.com/ichhabrecht/filefill/blob/main/README.md This snippet enables debug logging for the Filefill extension by configuring the TYPO3 logger. It directs debug-level logs to a specific file using the FileWriter. ```php $GLOBALS['TYPO3_CONF_VARS']['LOG']['IchHabRecht']['Filefill'] = [ 'writerConfiguration' => [ \TYPO3\CMS\Core\Log\LogLevel::DEBUG => [ \TYPO3\CMS\Core\Log\Writer\FileWriter::class => [ 'logFileInfix' => 'filefill', ], ], ], ]; ``` -------------------------------- ### Placehold.co Resource Handler - Generate Placeholders Source: https://context7.com/ichhabrecht/filefill/llms.txt Generates placeholder images using the placehold.co service via the PlaceholdResource handler. It creates images with dimensions derived from file metadata. Supports internal API for checking file handleability and generating image content. ```php // Configuration for placehold.co resource $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['filefill']['storages'][1] = [ [ 'identifier' => 'placehold', // No configuration required, checkbox is just a placeholder ], ]; // Supported file extensions: avif, gif, jpeg, jpg, png, svg, webp // Internal API usage use IchHabRecht\Filefill\Resource\Handler\PlaceholdResource; $placeholdResource = new PlaceholdResource(null); // Check if file can be handled (must be FileInterface with supported extension) $canHandle = $placeholdResource->hasFile( '/user_upload/banner.jpg', 'fileadmin/user_upload/banner.jpg', $fileObject // FileInterface with width=1920, height=400 ); // Returns: true for image files, false for other file types // Generate placeholder image from placehold.co $imageContent = $placeholdResource->getFile( '/user_upload/banner.jpg', 'fileadmin/user_upload/banner.jpg', $fileObject ); // Fetches: https://placehold.co/1920x400.jpg // Returns: Image binary content ``` -------------------------------- ### Reset Missing File Flag with CLI Source: https://context7.com/ichhabrecht/filefill/llms.txt Resets the 'missing' flag on files in the sys_file table, allowing filefill to attempt fetching them again on the next access. This command can be run for all enabled storages or specific ones. ```bash vendor/bin/typo3 filefill:reset # Reset missing flag for specific storage only vendor/bin/typo3 filefill:reset --storage=1 vendor/bin/typo3 filefill:reset -s 1 ``` -------------------------------- ### Registering a Resource Handler in TYPO3 Source: https://github.com/ichhabrecht/filefill/blob/main/README.md This snippet demonstrates how to register a custom resource handler in the TYPO3 configuration. It defines the identifier, the handler class, and the TCA configuration for the backend field. ```php $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['filefill']['resourceHandler']['identifierName'] = [ 'title' => 'Name of the resource', 'handler' => \Vendor\Extension\Resource\ResourceHandler::class, 'config' => [ 'label' => 'Name of the resource', 'config' => [ 'type' => 'check', 'default' => 1, ], ], ]; ``` -------------------------------- ### RemoteResourceInterface Definition Source: https://context7.com/ichhabrecht/filefill/llms.txt The interface contract required for all custom resource handlers to interact with the Filefill system. ```php namespace IchHabRecht\Filefill\Resource; use TYPO3\CMS\Core\Resource\FileInterface; interface RemoteResourceInterface { public function hasFile($fileIdentifier, $filePath, ?FileInterface $fileObject = null): bool; public function getFile($fileIdentifier, $filePath, ?FileInterface $fileObject = null); } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.