Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ vich_uploader:
This is the minimal amount of configuration needed in order to describe a
working mapping.

> [!NOTE]
> If the `upload_destination` parameter is missing, it this concatenated with

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"it this concatenated" doesn't make sense

> the `%kernel.project_dir%/public` prefix and the `uri_prefix`.

## Step 2: link the upload mapping to an entity

The final step is to create a link between the filesystem and the entity you
Expand Down
2 changes: 1 addition & 1 deletion src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ private function addMappingsSection(ArrayNodeDefinition $node): void
->prototype('array')
->children()
->scalarNode('uri_prefix')->defaultValue('/uploads')->end()
->scalarNode('upload_destination')->isRequired()->end()
->scalarNode('upload_destination')->end()
->arrayNode('namer')
->addDefaultsIfNotSet()
->beforeNormalization()
Expand Down
14 changes: 14 additions & 0 deletions src/DependencyInjection/VichUploaderExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public function load(array $configs, ContainerBuilder $container): void
$config = $this->processConfiguration($configuration, $configs);

$config = $this->fixDbDriverConfig($config);
$config = $this->fixUploadDestinationConfig($container, $config);
$config = $this->createNamerServices($container, $config);

// define a few parameters
Expand Down Expand Up @@ -200,6 +201,19 @@ protected function fixDbDriverConfig(array $config): array
return $config;
}

protected function fixUploadDestinationConfig(ContainerBuilder $container, array $config): array
{
// mapping with no declared upload_destination use the uri_prefix

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"use" -> "uses"

@laurentmuller laurentmuller Aug 26, 2025

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's the same as comment in fixDbDriverConfig() function. We must also update?

$prefix = $container->getParameter('kernel.project_dir') ?? '';
foreach ($config['mappings'] as &$mapping) {
if (!\array_key_exists('upload_destination', $mapping)) {
$mapping['upload_destination'] = $prefix.'/public/'.$mapping['uri_prefix'];
Comment thread
garak marked this conversation as resolved.
}
}

return $config;
}

protected function registerListeners(ContainerBuilder $container, array $config): void
{
$servicesMap = [
Expand Down