Skip to content

Commit dcf2027

Browse files
committed
Fix media url in data tab
1 parent 92bb873 commit dcf2027

File tree

2 files changed

+10
-19
lines changed

2 files changed

+10
-19
lines changed

ListBuilder/DynamicListBuilder.php

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function build(Dynamic $dynamic, string $locale): array
5151

5252
foreach ($entry as $key => $value) {
5353
if (Dynamic::TYPE_ATTACHMENT === $dynamic->getFieldType($key)) {
54-
$singleEntry[$key] = $this->getMediaUrls($value);
54+
$singleEntry[$key] = $this->getMediaUrls($value, $locale);
5555
} else {
5656
$singleEntry[$key] = $this->toString($value);
5757
}
@@ -95,15 +95,15 @@ private function toString($value): string
9595
/**
9696
* @param mixed $value
9797
*/
98-
private function getMediaUrls($value): string
98+
private function getMediaUrls($value, string $locale): string
9999
{
100100
if (\is_string($value)) {
101-
return $this->getMediaUrl($value);
101+
return $this->getMediaUrl($value, $locale);
102102
}
103103

104104
if (\is_array($value)) {
105105
foreach ($value as $key => $mediaId) {
106-
$value[$key] = $this->getMediaUrl($mediaId);
106+
$value[$key] = $this->getMediaUrl($mediaId, $locale);
107107
}
108108

109109
return \implode($this->delimiter, $value);
@@ -112,9 +112,9 @@ private function getMediaUrls($value): string
112112
return $this->toString($value);
113113
}
114114

115-
private function getMediaUrl(string $value): string
115+
private function getMediaUrl(string $value, string $locale): string
116116
{
117-
return \str_replace('{id}', $value, $this->getDownloadUrl());
117+
return \str_replace(['{id}', '{locale}'], [$value, $locale], $this->getDownloadUrl());
118118
}
119119

120120
/**
@@ -125,12 +125,13 @@ private function getDownloadUrl(): string
125125
if (null === $this->downloadUrl) {
126126
// The given id must be a number which we replace
127127
$idReplacerNumber = '875421';
128+
$localeToReplace = 'en';
128129

129-
$this->downloadUrl = \str_replace($idReplacerNumber, '{id}', $this->router->generate(
130-
'sulu_media.website.media.download',
130+
$this->downloadUrl = \str_replace([$idReplacerNumber, $localeToReplace], ['{id}', '{locale}'], $this->router->generate(
131+
'sulu_media.redirect',
131132
[
132-
'slug' => 'file',
133133
'id' => $idReplacerNumber,
134+
'locale' => $localeToReplace,
134135
],
135136
RouterInterface::ABSOLUTE_URL
136137
));

phpstan-baseline.neon

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,6 @@ parameters:
4040
count: 1
4141
path: Command/FormGeneratorCommand.php
4242

43-
-
44-
message: "#^Method Sulu\\\\Bundle\\\\FormBundle\\\\Command\\\\FormGeneratorCommand\\:\\:loadTestForm\\(\\) should return Sulu\\\\Bundle\\\\FormBundle\\\\Entity\\\\Form\\|null but returns mixed\\.$#"
45-
count: 1
46-
path: Command/FormGeneratorCommand.php
47-
4843
-
4944
message: "#^Property Sulu\\\\Bundle\\\\FormBundle\\\\Configuration\\\\FormConfiguration\\:\\:\\$adminMailConfiguration \\(Sulu\\\\Bundle\\\\FormBundle\\\\Configuration\\\\MailConfigurationInterface\\) does not accept Sulu\\\\Bundle\\\\FormBundle\\\\Configuration\\\\MailConfigurationInterface\\|null\\.$#"
5045
count: 1
@@ -1385,11 +1380,6 @@ parameters:
13851380
count: 2
13861381
path: Repository/FormRepository.php
13871382

1388-
-
1389-
message: "#^Method Sulu\\\\Bundle\\\\FormBundle\\\\Repository\\\\FormRepository\\:\\:loadById\\(\\) should return Sulu\\\\Bundle\\\\FormBundle\\\\Entity\\\\Form\\|null but returns mixed\\.$#"
1390-
count: 1
1391-
path: Repository/FormRepository.php
1392-
13931383
-
13941384
message: "#^Call to an undefined method Symfony\\\\Component\\\\HttpFoundation\\\\RequestStack\\:\\:getMasterRequest\\(\\)\\.$#"
13951385
count: 1

0 commit comments

Comments
 (0)