Skip to content

Commit a04e080

Browse files
committed
fix download_label_translation_domain in view
1 parent 77850dd commit a04e080

4 files changed

Lines changed: 17 additions & 5 deletions

File tree

src/Form/Type/VichFileType.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function __construct(
3131
protected readonly StorageInterface $storage,
3232
protected readonly UploadHandler $handler,
3333
protected readonly PropertyMappingFactory $factory,
34-
?PropertyAccessorInterface $propertyAccessor = null
34+
?PropertyAccessorInterface $propertyAccessor = null,
3535
) {
3636
$this->propertyAccessor = $propertyAccessor ?: PropertyAccess::createPropertyAccessor();
3737
}
@@ -120,9 +120,10 @@ public function buildView(FormView $view, FormInterface $form, array $options):
120120
$view->vars['download_uri'] = null;
121121
if ($options['download_uri'] && $object) {
122122
$view->vars['download_uri'] = $this->resolveUriOption($options['download_uri'], $object, $form);
123+
123124
$view->vars = \array_replace(
124125
$view->vars,
125-
$this->resolveDownloadLabel($options['download_label'], $object, $form)
126+
$this->resolveDownloadLabel($options['download_label'], $object, $form, $options)
126127
);
127128
}
128129

@@ -152,7 +153,7 @@ protected function resolveUriOption(mixed $uriOption, object $object, FormInterf
152153
return $uriOption;
153154
}
154155

155-
protected function resolveDownloadLabel(mixed $downloadLabel, object $object, FormInterface $form): array
156+
protected function resolveDownloadLabel(mixed $downloadLabel, object $object, FormInterface $form, $options): array
156157
{
157158
if (true === $downloadLabel) {
158159
$fieldName = $this->getFieldName($form);
@@ -182,6 +183,9 @@ protected function resolveDownloadLabel(mixed $downloadLabel, object $object, Fo
182183
];
183184
}
184185

185-
return ['download_label' => $downloadLabel];
186+
return [
187+
'download_label' => $downloadLabel,
188+
'download_label_translation_domain' => $options['download_label_translation_domain'] ?? $options['translation_domain'],
189+
];
186190
}
187191
}

src/Form/Type/VichImageType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public function buildView(FormView $view, FormInterface $form, array $options):
8686

8787
$view->vars = \array_replace(
8888
$view->vars,
89-
$this->resolveDownloadLabel($options['download_label'], $object, $form)
89+
$this->resolveDownloadLabel($options['download_label'], $object, $form, $options)
9090
);
9191

9292
$view->vars['download_uri'] = $this->resolveUriOption($options['download_uri'], $object, $form);

tests/Form/Type/VichFileTypeTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ public static function buildViewDataProvider(): array
128128
[
129129
'object' => $object,
130130
'download_label' => 'custom label',
131+
'download_label_translation_domain' => null,
131132
'download_uri' => 'resolved-uri',
132133
'value' => null,
133134
'attr' => [],
@@ -174,6 +175,7 @@ public static function buildViewDataProvider(): array
174175
[
175176
'object' => $object,
176177
'download_label' => 'download',
178+
'download_label_translation_domain' => null,
177179
'download_uri' => '/download/image.jpeg',
178180
'value' => null,
179181
'attr' => [],
@@ -190,6 +192,7 @@ public static function buildViewDataProvider(): array
190192
[
191193
'object' => $object,
192194
'download_label' => 'download',
195+
'download_label_translation_domain' => null,
193196
'download_uri' => 'custom-uri',
194197
'value' => null,
195198
'attr' => [],

tests/Form/Type/VichImageTypeTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public static function buildViewDataProvider(): array
3636
'object' => $object,
3737
'download_uri' => 'resolved-uri',
3838
'download_label' => 'download',
39+
'download_label_translation_domain' => null,
3940
'image_uri' => null,
4041
'show_download_link' => true,
4142
'value' => null,
@@ -75,6 +76,7 @@ public static function buildViewDataProvider(): array
7576
'object' => $object,
7677
'download_uri' => false,
7778
'download_label' => 'download',
79+
'download_label_translation_domain' => null,
7880
'image_uri' => 'resolved-uri',
7981
'show_download_link' => false,
8082
'value' => null,
@@ -95,6 +97,7 @@ public static function buildViewDataProvider(): array
9597
'object' => $object,
9698
'download_uri' => 'custom-uri',
9799
'download_label' => 'download',
100+
'download_label_translation_domain' => null,
98101
'show_download_link' => true,
99102
'image_uri' => 'resolved-uri',
100103
'value' => null,
@@ -115,6 +118,7 @@ public static function buildViewDataProvider(): array
115118
'object' => $object,
116119
'download_uri' => 'custom-uri',
117120
'download_label' => 'download',
121+
'download_label_translation_domain' => null,
118122
'show_download_link' => true,
119123
'image_uri' => 'image_uri',
120124
'value' => null,
@@ -135,6 +139,7 @@ public static function buildViewDataProvider(): array
135139
'object' => $object,
136140
'download_uri' => 'custom-uri',
137141
'download_label' => 'download',
142+
'download_label_translation_domain' => null,
138143
'show_download_link' => true,
139144
'image_uri' => 'prefix-resolved-uri',
140145
'value' => null,

0 commit comments

Comments
 (0)