Skip to content

Commit b3a9c99

Browse files
committed
Updates for file handeling and urls
1 parent 2869e13 commit b3a9c99

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

src/AssetApiServiceBase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function getFileData($file) {
4242
public function getRelativePath(string $path) {
4343
$replaced_relative_path = '';
4444
if ($path !== '') {
45-
$transformed = $this->fileUrlGenerator->transformRelative($file_url);
45+
$transformed = $this->fileUrlGenerator->transformRelative($path);
4646
$relative_path = urldecode($transformed);
4747
// TODO: replace with actual public files path.
4848
$replaced_relative_path = str_replace('/sites/default/files/', '', $relative_path);

src/ImageApiService.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,12 @@ public function getImageData($file, $image_styles = []) {
6464
if ($crop) {
6565
$anchor = $this->focalPointManager->absoluteToRelative($crop->x->value, $crop->y->value, $image_file->getWidth(), $image_file->getHeight());
6666
}
67+
$uri = $file->getFileUri();
68+
$url = $this->fileUrlGenerator->generateAbsoluteString($uri);
6769
$data = [
68-
'uri' => $file->getFileUri(),
69-
'url' => $file->url(),
70-
'relativePath' => $this->getRelativePath($file->url()),
70+
'uri' => $uri,
71+
'url' => $url,
72+
'relativePath' => $this->getRelativePath($url),
7173
'origSize' => [
7274
'width' => $image_file->getWidth(),
7375
'height' => $image_file->getHeight(),
@@ -78,6 +80,7 @@ public function getImageData($file, $image_styles = []) {
7880
foreach ($image_styles as $style_name) {
7981
$style = ImageStyle::load($style_name);
8082

83+
// todo: check style exists
8184
$url = $style->buildUrl($file->getFileUri());
8285

8386
// Remove an h query param.

0 commit comments

Comments
 (0)