Skip to content

Commit

Permalink
Fixes dustin10#1228, metadata loading from config/vich_uploader direc…
Browse files Browse the repository at this point in the history
…tory (dustin10#1230)

Fix dustin10#1228, metadata loading from config/vich_uploader directory
  • Loading branch information
bertrandseurot authored Oct 11, 2021
1 parent d6fec65 commit f4ff482
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 6 deletions.
17 changes: 14 additions & 3 deletions docs/mapping/xml.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,19 @@ format and comes with the following syntax to declare your uploadable fields:
</vich_uploader>
```

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:
Expand All @@ -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'}
```
Expand Down
17 changes: 14 additions & 3 deletions docs/mapping/yaml.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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'}
```
Expand Down
8 changes: 8 additions & 0 deletions src/DependencyInjection/VichUploaderExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down

0 comments on commit f4ff482

Please sign in to comment.