inspiredminds / contao-file-usage
Contao extension that allows you to search for references of files in the database assisted file manager.
Fund package maintenance!
fritzmg
Installs: 4 631
Dependents: 0
Suggesters: 0
Security: 0
Stars: 12
Watchers: 5
Forks: 4
Open Issues: 2
Type:contao-bundle
Requires
- php: >=8.1
- contao/core-bundle: ^4.13 || ^5.0
- doctrine/dbal: ^3.0
- khill/php-duration: ^1.0
- symfony/cache: ^5.4 || ^6.4 || ^7.1
- symfony/config: ^5.4 || ^6.4 || ^7.1
- symfony/dependency-injection: ^5.4 || ^6.4 || ^7.1
- symfony/http-kernel: ^5.4 || ^6.4 || ^7.1
Requires (Dev)
- contao/easy-coding-standard: ^6.0
- contao/rector: ^1.0
README
Contao File Usage
This Contao extension allows you to find and display file references of your files managed by the file manager. For each file in the file manager there will be a new operation ( or ).
This operation will then show you any references of this file that this extension finds in the database, with links to the original data record, if available.
The search results are cached indefinitely. You can force to fetch new search results with the Refresh button. However, depending on the size of your database this might take a while and might not be able to finish within the HTTP request. In this case you will need to rely on the cronjob or command.
You can also use the "Unused files" global operation in order to find any database assisted files that aren't referenced anywhere (at least according to the search results).
File Replacements
This extension also replaces Contao's fileTree
widget with its own implementation, showing an additional button with
which you can replace the file references found for this file with a new reference.
Cronjob
As previously mentioned the search results are cached. In order for the cache to always be up to date for at least 24 hours this extension implements a daily cronjob. However, the cronjob is only run on the command line interface, so make sure that you have set up Contao's cronjob accordingly.
Command
You can also warm up the file usage result cache from the command line, using the contao_file_usage:warmup
command.
Custom Providers
Currently this extension can find any references created by the fileTree
input field of any (database based) DCA and
it can find any references from {{file::*}}
, {{picture::*}}
and {{figure::*}}
insert tags in any text based fields
in the database. It can also find src="…"
references in the database where only the path is used in textarea
fields.
If you want to expand this search to other locations you can implement your own file usage provider by implementing
the FileUsageProviderInterface
.
// src/FileUsage/FoobarProvider.php use InspiredMinds\ContaoFileUsage\Provider\FileUsageProviderInterface; use InspiredMinds\ContaoFileUsage\Result\DatabaseReferenceResult; use InspiredMinds\ContaoFileUsage\Result\ResultsCollection; class FoobarProvider implements FileUsageProviderInterface { public function find(): ResultsCollection { $collection = new ResultsCollection(); // Additional database search // … $collection->addResult(new DatabaseReferenceResult($table, $field, $id)); return $collection; } }
That is all you need to do, if you enabled autoconfigure
for your service. Otherwise you will also need to tag the
service with contao_file_usage.provider
manually.
You might want or need to implement a new result container using the ResultInterface
for your purposes (e.g. if your
provider looks in the contents of files, rather than the database for example, which this extension currently does not
do by default). In your interface you will need to reference the Twig template that should be used when rendering the
result in the back end:
// src/FileUsage/CustomFileUsageResult.php use InspiredMinds\ContaoFileUsage\Result\ResultInterface; class CustomFileUsageResult implements ResultInterface { public function __construct( // Your result data ) { } public function getTemplate(): string { return '@Foobar/my_file_usage_result.html.twig'; } }