Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
5 changes: 5 additions & 0 deletions docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ vich_uploader:
This is the minimal amount of configuration needed in order to describe a
working mapping.

**Note:**
Comment thread
laurentmuller marked this conversation as resolved.
Outdated

> 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
4 changes: 4 additions & 0 deletions src/Mapping/PropertyMappingResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ public function resolve(object|array $obj, string $fieldName, array $mappingData
}

$config = $this->mappings[$mappingData['mapping']];
if (!\array_key_exists('upload_destination', $config)) {
$prefix = $this->container->getParameter('kernel.project_dir') ?? '';
$config['upload_destination'] = $prefix.'/public/'.$config['uri_prefix'];
}
$fileProperty = $mappingData['propertyName'] ?? $fieldName;
$fileNameProperty = empty($mappingData['fileNameProperty']) ? $fileProperty.$this->defaultFilenameAttributeSuffix : $mappingData['fileNameProperty'];

Expand Down