diff --git a/.composer-require-checker.json b/.composer-require-checker.json index 68d9d79..1fbb404 100644 --- a/.composer-require-checker.json +++ b/.composer-require-checker.json @@ -7,6 +7,7 @@ "Contao\\ManagerPlugin\\Bundle\\Parser\\ParserInterface", "Contao\\ManagerPlugin\\Routing\\RoutingPluginInterface", "MetaModels\\ContaoFrontendEditingBundle\\MetaModelsContaoFrontendEditingBundle", + "InspiredMinds\\ContaoFileUsage\\ContaoFileUsageBundle", "InspiredMinds\\ContaoFileUsage\\Provider\\FileUsageProviderInterface", "InspiredMinds\\ContaoFileUsage\\Result\\FileTreeMultipleResult", "InspiredMinds\\ContaoFileUsage\\Result\\FileTreeSingleResult", diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index 2081b4e..d945b14 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -3,7 +3,7 @@ /** * This file is part of MetaModels/attribute_file. * - * (c) 2012-2023 The MetaModels team. + * (c) 2012-2025 The MetaModels team. * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -13,7 +13,7 @@ * @package MetaModels/attribute_file * @author Sven Baumann * @author Ingolf Steinhardt - * @copyright 2012-2023 The MetaModels team. + * @copyright 2012-2025 The MetaModels team. * @license https://github.com/MetaModels/attribute_file/blob/master/LICENSE LGPL-3.0-or-later * @filesource */ @@ -45,7 +45,7 @@ final class Configuration implements ConfigurationInterface */ public function __construct(bool $debug) { - $this->debug = $debug; + $this->debug = $debug; } /** @@ -61,7 +61,9 @@ public function getConfigTreeBuilder(): TreeBuilder $children->booleanNode('enable_cache')->defaultValue(!$this->debug)->end(); $children ->scalarNode('cache_dir') - ->defaultValue('%metamodels.cache_dir%' . DIRECTORY_SEPARATOR . 'attribute_file'); + ->defaultValue('%metamodels.cache_dir%' . DIRECTORY_SEPARATOR . 'attribute_file') + ->end(); + $children->booleanNode('file_usage')->defaultValue(false)->end(); return $treeBuilder; } diff --git a/src/DependencyInjection/MetaModelsAttributeFileExtension.php b/src/DependencyInjection/MetaModelsAttributeFileExtension.php index 1e87d9c..38d6790 100644 --- a/src/DependencyInjection/MetaModelsAttributeFileExtension.php +++ b/src/DependencyInjection/MetaModelsAttributeFileExtension.php @@ -3,7 +3,7 @@ /** * This file is part of MetaModels/attribute_file. * - * (c) 2012-2024 The MetaModels team. + * (c) 2012-2025 The MetaModels team. * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -14,13 +14,14 @@ * @author Christian Schiffler * @author Sven Baumann * @author Ingolf Steinhardt - * @copyright 2012-2024 The MetaModels team. + * @copyright 2012-2025 The MetaModels team. * @license https://github.com/MetaModels/attribute_file/blob/master/LICENSE LGPL-3.0-or-later * @filesource */ namespace MetaModels\AttributeFileBundle\DependencyInjection; +use InspiredMinds\ContaoFileUsage\ContaoFileUsageBundle; use MetaModels\AttributeFileBundle\EventListener\DcGeneral\Table\DcaSetting\FileWidgetModeOptions; use MetaModels\ContaoFrontendEditingBundle\MetaModelsContaoFrontendEditingBundle; use Symfony\Component\Cache\Adapter\ArrayAdapter; @@ -57,18 +58,23 @@ public function load(array $configs, ContainerBuilder $container): void $config = $this->processConfiguration($configuration, $configs); $this->buildCacheService($container, $config); - $frontendEditing = false; - $bundles = $container->getParameter('kernel.bundles'); assert(is_array($bundles)); - // Load configuration for the frontend editing. + + // Load configuration for the frontend editing extension. + $frontendEditing = false; if (in_array(MetaModelsContaoFrontendEditingBundle::class, $bundles, true)) { $frontendEditing = true; $loader->load('frontend_editing/event_listener.yml'); } - $this->addFrontendEditingArgument($container, $frontendEditing); + // Load configuration for the file usage extension. + if (in_array(ContaoFileUsageBundle::class, $bundles, true) && (bool) ($config['file_usage'] ?? false)) { + $loader->load('file_usage/services.yml'); + } + + // Schema manager $typeNames = $container->hasParameter('metamodels.managed-schema-type-names') ? $container->getParameter('metamodels.managed-schema-type-names') : null; @@ -96,9 +102,9 @@ public function getConfiguration(array $config, ContainerBuilder $container): ?C * * @return void */ - private function buildCacheService(ContainerBuilder $container, array $config) + private function buildCacheService(ContainerBuilder $container, array $config): void { - // if cache disabled, swap it out with the dummy cache. + // If cache disabled, swap it out with the dummy cache. if (!$config['enable_cache']) { $cache = $container->getDefinition('metamodels.attribute_file.cache_system'); $cache->setClass(ArrayAdapter::class); diff --git a/src/Resources/config/file_usage/services.yml b/src/Resources/config/file_usage/services.yml new file mode 100644 index 0000000..63e41d7 --- /dev/null +++ b/src/Resources/config/file_usage/services.yml @@ -0,0 +1,11 @@ +services: + MetaModels\AttributeFileBundle\FileUsage\FileUsageProvider: + public: true + arguments: + $factory: '@metamodels.factory' + $urlGenerator: '@router' + $requestStack: '@request_stack' + $csrfTokenManager: '@contao.csrf.token_manager' + $csrfTokenName: '%contao.csrf_token_name%' + tags: + - { name: contao_file_usage.provider } diff --git a/src/Resources/config/services.yml b/src/Resources/config/services.yml index 9fb8c94..9c59da6 100644 --- a/src/Resources/config/services.yml +++ b/src/Resources/config/services.yml @@ -32,14 +32,3 @@ services: - '@metamodels.table_manipulator' tags: - name: contao.migration - - MetaModels\AttributeFileBundle\FileUsage\FileUsageProvider: - public: true - arguments: - $factory: '@metamodels.factory' - $urlGenerator: '@router' - $requestStack: '@request_stack' - $csrfTokenManager: '@contao.csrf.token_manager' - $csrfTokenName: '%contao.csrf_token_name%' - tags: - - { name: contao_file_usage.provider }