Skip to content

Commit 9d14531

Browse files
committed
First PR for #1526.
1 parent daa56f2 commit 9d14531

3 files changed

Lines changed: 10 additions & 1 deletion

File tree

docs/usage.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ vich_uploader:
4141
This is the minimal amount of configuration needed in order to describe a
4242
working mapping.
4343
44+
**Note:**
45+
46+
> If the `upload_destination` parameter is missing, it this concatenated with
47+
> the `%kernel.project_dir%/public` prefix and the `uri_prefix`.
48+
4449
## Step 2: link the upload mapping to an entity
4550

4651
The final step is to create a link between the filesystem and the entity you

src/DependencyInjection/Configuration.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ private function addMappingsSection(ArrayNodeDefinition $node): void
103103
->prototype('array')
104104
->children()
105105
->scalarNode('uri_prefix')->defaultValue('/uploads')->end()
106-
->scalarNode('upload_destination')->isRequired()->end()
106+
->scalarNode('upload_destination')->end()
107107
->arrayNode('namer')
108108
->addDefaultsIfNotSet()
109109
->beforeNormalization()

src/Mapping/PropertyMappingResolver.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ public function resolve(object|array $obj, string $fieldName, array $mappingData
3333
}
3434

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

0 commit comments

Comments
 (0)