From f4ff4822323e6c23b1819359726dbf88a7478b89 Mon Sep 17 00:00:00 2001 From: Bertrand Date: Mon, 11 Oct 2021 10:17:46 +0200 Subject: [PATCH] Fixes #1228, metadata loading from config/vich_uploader directory (#1230) Fix #1228, metadata loading from config/vich_uploader directory --- docs/mapping/xml.md | 17 ++++++++++++++--- docs/mapping/yaml.md | 17 ++++++++++++++--- .../VichUploaderExtension.php | 8 ++++++++ 3 files changed, 36 insertions(+), 6 deletions(-) diff --git a/docs/mapping/xml.md b/docs/mapping/xml.md index 07b98f4f..d3c1ef22 100644 --- a/docs/mapping/xml.md +++ b/docs/mapping/xml.md @@ -13,8 +13,19 @@ format and comes with the following syntax to declare your uploadable fields: ``` -To be automatically found, the mapping configuration MUST be in the `config/vich_uploader` -directory of the bundle containing the entity you want to describe. +To be automatically found, the mapping configuration MUST be in the `config/vich_uploader` directory +of your symfony application, and the root namespace MUST be the de-facto standard `App` namespace. +Third-party bundles providing configuration must follow the same rule in their own directory. + +Turning off auto-detection will disable this discovery method: + +```yaml +# config/packages/vich_uploader.yaml or app/config/config.yml +vich_uploader: + # ... + metadata: + auto_detection: false +``` If you need the mapping elsewhere, you need to add some configuration. In the following example, the configuration is placed in the `config/acme` directory: @@ -24,7 +35,7 @@ In the following example, the configuration is placed in the `config/acme` direc vich_uploader: # ... metadata: - auto_detection: false + auto_detection: false # omit this line if the previously described auto-discovery is still needed directories: - {path: '%kernel.project_dir%/config/acme', namespace_prefix: 'Acme'} ``` diff --git a/docs/mapping/yaml.md b/docs/mapping/yaml.md index 1d99aa64..6a283c55 100644 --- a/docs/mapping/yaml.md +++ b/docs/mapping/yaml.md @@ -16,8 +16,19 @@ Acme\DemoBundle\Entity\Product: dimensions: imageDimensions ``` -To be automatically found, the mapping configuration MUST be in the `config/vich_uploader` -directory of the bundle containing the entity you want to describe. +To be automatically found, the mapping configuration MUST be in the `config/vich_uploader` directory +of your symfony application, and the root namespace MUST be the de-facto standard `App` namespace. +Third-party bundles providing configuration must follow the same rule in their own directory. + +Turning off auto-detection will disable this discovery method: + +```yaml +# config/packages/vich_uploader.yaml or app/config/config.yml +vich_uploader: + # ... + metadata: + auto_detection: false +``` If you need the mapping elsewhere, you need to add some configuration. In the following example, the configuration is placed in the `config/acme` directory: @@ -27,7 +38,7 @@ In the following example, the configuration is placed in the `config/acme` direc vich_uploader: # ... metadata: - auto_detection: false + auto_detection: false # omit this line if the previously described auto-discovery is still needed directories: - {path: '%kernel.project_dir%/config/acme', namespace_prefix: 'Acme'} ``` diff --git a/src/DependencyInjection/VichUploaderExtension.php b/src/DependencyInjection/VichUploaderExtension.php index e06c9aff..2d87fec7 100644 --- a/src/DependencyInjection/VichUploaderExtension.php +++ b/src/DependencyInjection/VichUploaderExtension.php @@ -91,6 +91,14 @@ protected function registerMetadataDirectories(ContainerBuilder $container, arra // directories $directories = []; if ($config['metadata']['auto_detection']) { + $projectDir = $container->getParameter('kernel.project_dir'); + if (\is_string($projectDir)) { + $appConfigDirectory = $projectDir.'/config/vich_uploader'; + if (\is_dir($appConfigDirectory)) { + $directories['App'] = $appConfigDirectory; + } + } + foreach ($bundles as $class) { $ref = new \ReflectionClass($class); $directory = \dirname($ref->getFileName()).'/../config/vich_uploader';