Skip to content

Commit ad2f834

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

File tree

1 file changed

+10
-27
lines changed

1 file changed

+10
-27
lines changed

ListBuilder/DynamicListBuilder.php

Lines changed: 10 additions & 27 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, $locale): string
9999
{
100100
if (\is_string($value)) {
101101
return $this->getMediaUrl($value);
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,30 +112,13 @@ 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());
118-
}
119-
120-
/**
121-
* For performance generate route only once.
122-
*/
123-
private function getDownloadUrl(): string
124-
{
125-
if (null === $this->downloadUrl) {
126-
// The given id must be a number which we replace
127-
$idReplacerNumber = '875421';
128-
129-
$this->downloadUrl = \str_replace($idReplacerNumber, '{id}', $this->router->generate(
130-
'sulu_media.website.media.download',
131-
[
132-
'slug' => 'file',
133-
'id' => $idReplacerNumber,
134-
],
135-
RouterInterface::ABSOLUTE_URL
136-
));
137-
}
138-
139-
return $this->downloadUrl;
117+
return $this->router->generate('sulu_media.redirect', [
118+
'id' => $value,
119+
'locale' => $locale,
120+
],
121+
RouterInterface::ABSOLUTE_URL
122+
);
140123
}
141124
}

0 commit comments

Comments
 (0)