Skip to content

Commit a3df260

Browse files
committed
Merge branch 'hotfix/fix_servieces_file_usage' into 'feature/2.3.0'
Fix services for file usage See merge request metamodels/attribute_translatedfile!51
2 parents 973c2ba + ad9e03d commit a3df260

File tree

5 files changed

+95
-25
lines changed

5 files changed

+95
-25
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
/**
4+
* This file is part of MetaModels/attribute_translatedfile.
5+
*
6+
* (c) 2012-2025 The MetaModels team.
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*
11+
* This project is provided in good faith and hope to be usable by anyone.
12+
*
13+
* @package MetaModels/attribute_translatedfile
14+
* @author Ingolf Steinhardt <info@e-spin.de>
15+
* @copyright 2012-2025 The MetaModels team.
16+
* @license https://github.com/MetaModels/attribute_translatedfile/blob/master/LICENSE LGPL-3.0-or-later
17+
* @filesource
18+
*/
19+
20+
declare(strict_types=1);
21+
22+
namespace MetaModels\AttributeTranslatedFileBundle\DependencyInjection;
23+
24+
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
25+
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
26+
use Symfony\Component\Config\Definition\ConfigurationInterface;
27+
28+
/**
29+
* Adds the Contao configuration structure.
30+
*/
31+
final class Configuration implements ConfigurationInterface
32+
{
33+
/**
34+
* {@inheritDoc}
35+
*/
36+
public function getConfigTreeBuilder(): TreeBuilder
37+
{
38+
$treeBuilder = new TreeBuilder('metamodels_attribute_translatedfile');
39+
40+
$rootNode = $treeBuilder->getRootNode();
41+
assert($rootNode instanceof ArrayNodeDefinition);
42+
$children = $rootNode->children();
43+
$children->booleanNode('file_usage')->defaultValue(false)->end();
44+
45+
return $treeBuilder;
46+
}
47+
}

src/DependencyInjection/MetaModelsAttributeTranslatedFileExtension.php

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/**
44
* This file is part of MetaModels/attribute_translatedfile.
55
*
6-
* (c) 2012-2024 The MetaModels team.
6+
* (c) 2012-2025 The MetaModels team.
77
*
88
* For the full copyright and license information, please view the LICENSE
99
* file that was distributed with this source code.
@@ -14,18 +14,26 @@
1414
* @author David Molineus <david.molineus@netzmacht.de>
1515
* @author Sven Baumann <baumann.sv@gmail.com>
1616
* @author Ingolf Steinhardt <info@e-spin.de>
17-
* @copyright 2012-2024 The MetaModels team.
17+
* @copyright 2012-2025 The MetaModels team.
1818
* @license https://github.com/MetaModels/attribute_translatedfile/blob/master/LICENSE LGPL-3.0-or-later
1919
* @filesource
2020
*/
2121

2222
namespace MetaModels\AttributeTranslatedFileBundle\DependencyInjection;
2323

24+
use InspiredMinds\ContaoFileUsage\ContaoFileUsageBundle;
25+
use MetaModels\AttributeTranslatedFileBundle\DependencyInjection\Configuration;
26+
use Symfony\Component\Config\Definition\ConfigurationInterface;
2427
use Symfony\Component\Config\FileLocator;
2528
use Symfony\Component\DependencyInjection\ContainerBuilder;
2629
use Symfony\Component\DependencyInjection\Extension\Extension;
2730
use Symfony\Component\DependencyInjection\Loader;
2831

32+
use function assert;
33+
use function in_array;
34+
use function is_array;
35+
use function is_bool;
36+
2937
/**
3038
* This is the class that loads and manages the bundle configuration
3139
*
@@ -43,13 +51,33 @@ public function load(array $configs, ContainerBuilder $container): void
4351
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
4452
$loader->load('factory.yml');
4553
$loader->load('event_listeners.yml');
46-
$loader->load('services.yml');
4754

55+
$configuration = $this->getConfiguration($configs, $container);
56+
assert($configuration instanceof Configuration);
57+
$config = $this->processConfiguration($configuration, $configs);
58+
59+
$bundles = $container->getParameter('kernel.bundles');
60+
assert(is_array($bundles));
61+
62+
// Load configuration for the file usage extension.
63+
if (in_array(ContaoFileUsageBundle::class, $bundles, true) && (bool) ($config['file_usage'] ?? false)) {
64+
$loader->load('file_usage/services.yml');
65+
}
66+
67+
// Schema manager.
4868
$typeNames = $container->hasParameter('metamodels.managed-schema-type-names')
4969
? $container->getParameter('metamodels.managed-schema-type-names')
5070
: null;
51-
$managedSchemaTypeNames = \is_array($typeNames) ? $typeNames : [];
71+
$managedSchemaTypeNames = is_array($typeNames) ? $typeNames : [];
5272
$managedSchemaTypeNames[] = 'translatedfile';
5373
$container->setParameter('metamodels.managed-schema-type-names', $managedSchemaTypeNames);
5474
}
75+
76+
/**
77+
* {@inheritDoc}
78+
*/
79+
public function getConfiguration(array $config, ContainerBuilder $container): ?ConfigurationInterface
80+
{
81+
return new Configuration();
82+
}
5583
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
services:
2+
MetaModels\AttributeTranslatedFileBundle\FileUsage\FileUsageProvider:
3+
public: true
4+
arguments:
5+
$factory: '@metamodels.factory'
6+
$urlGenerator: '@router'
7+
$requestStack: '@request_stack'
8+
$csrfTokenManager: '@contao.csrf.token_manager'
9+
$csrfTokenName: '%contao.csrf_token_name%'
10+
tags:
11+
- { name: contao_file_usage.provider }
12+

src/Resources/config/services.yml

Lines changed: 0 additions & 11 deletions
This file was deleted.

tests/DependencyInjection/MetaModelsAttributeTranslatedFileExtensionTest.php

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/**
44
* This file is part of MetaModels/attribute_translatedfile.
55
*
6-
* (c) 2012-2024 The MetaModels team.
6+
* (c) 2012-2025 The MetaModels team.
77
*
88
* For the full copyright and license information, please view the LICENSE
99
* file that was distributed with this source code.
@@ -15,23 +15,16 @@
1515
* @author Sven Baumann <baumann.sv@gmail.com>
1616
* @author Christian Schiffler <c.schiffler@cyberspectrum.de>
1717
* @author Ingolf Steinhardt <info@e-spin.de>
18-
* @copyright 2012-2024 The MetaModels team.
18+
* @copyright 2012-2025 The MetaModels team.
1919
* @license https://github.com/MetaModels/attribute_translatedfile/blob/master/LICENSE LGPL-3.0-or-later
2020
* @filesource
2121
*/
2222

2323
namespace MetaModels\AttributeTranslatedFileBundle\Test\DependencyInjection;
2424

25-
use MetaModels\AttributeTranslatedFileBundle\Attribute\AttributeOrderTypeFactory;
26-
use MetaModels\AttributeTranslatedFileBundle\Attribute\AttributeTypeFactory;
2725
use MetaModels\AttributeTranslatedFileBundle\DependencyInjection\MetaModelsAttributeTranslatedFileExtension;
28-
use MetaModels\AttributeTranslatedFileBundle\EventListener\BuildAttributeListener;
29-
use MetaModels\AttributeTranslatedFileBundle\EventListener\BuildDataDefinitionListener;
30-
use MetaModels\AttributeTranslatedFileBundle\EventListener\DcGeneral\Table\Attribute\RemoveTypeOptions;
3126
use MetaModels\AttributeTranslatedFileBundle\EventListener\DcGeneral\Table\DcaSetting\FileWidgetModeOptions;
32-
use MetaModels\AttributeTranslatedFileBundle\EventListener\DcGeneral\Table\FilterSetting\RemoveAttIdOptions;
33-
use MetaModels\AttributeTranslatedFileBundle\EventListener\Factory\AddAttributeInformation;
34-
use MetaModels\AttributeTranslatedFileBundle\EventListener\ImageSizeOptionsProvider;
27+
use MetaModels\AttributeTranslatedFileBundle\MetaModelsAttributeTranslatedFileBundle;
3528
use PHPUnit\Framework\TestCase;
3629
use Symfony\Component\DependencyInjection\ContainerBuilder;
3730
use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;
@@ -57,6 +50,7 @@ public function testInstantiation(): void
5750
public function testFactoryIsRegistered(): void
5851
{
5952
$container = new ContainerBuilder();
53+
$container->setParameter('kernel.bundles', [MetaModelsAttributeTranslatedFileBundle::class]);
6054

6155
$extension = new MetaModelsAttributeTranslatedFileExtension();
6256
$extension->load([], $container);

0 commit comments

Comments
 (0)