Setting up my first FRED site. It’s been slow going!
I’ve got an image TV set up as a fred TV, so it shows up in the Settings sidebar. When I select an image, it shows up just fine with the thumbnail, but after saving, the file path is mangled. I have the TV set to a media source with the path “assets/site/”. When I select an image, it gets entered as “assets/site/images/imagename.jpg” in the FRED image field. But after saving, the first letter of “images” gets chopped off, along with the media source path, so the the url gets saved as “mages/imagename.jpg”.
What’s causing this? FRED is removing the media source path up front, which is correct, but it’s also removing the first letter of the subfolder. It’s like it’s expecting the first character of the subfolder to be a slash, so it deletes it.
UPDATE: If I select an image in a different subfolder, the path gets saved correctly. It’s only when I select an image inside the folder called “images” that this happens!
FYI: Even though I have the media source specified in the fred.media.source property of the TV, when I click the folder icon to go into the FRED media manager, the specified media source isn’t the only media source shown.
I tried to reproduce the behavior, but wasn’t able to.
Could you provide the exact settings your are using for this TV (for example “Input Type”, etc.)
Also, there is this issue on Github that is somewhat similar. It concerns uploaded images, but the first letter of the path is also missing.
I believe this syntax is wrong.
Using fred.mediaSource seems to work. (The value has to be the name of the Media-Source and not the ID.)
Site is running MODX 2.8.7 in a MODX Cloud, FRED 1.3.0-pl, PHP 8.1.17.
I set up a new media source pointing directly to the images folder:
assets/site/images/
and set up a duplicate TV using that source. Now:
I selected the same image for both image TVs in FRED. Image path is:
“/assets/site/images/test–stuff/food-gradients-03.jpg”
The first TV changes that to:
“assets/site/mages/test–stuff/food-gradients-03.jpg” (no “i” in "images)
and the second TV (“Images” media source) changes it to:
“assets/site/images/–stuff/food-gradients-03.jpg” (“images” is correct but “test” disappears!!)
For the second TV, selecting other images in any folder except “test–stuff” works. In the first TV, any image selected inside the “images” folder or its own subfolders changes “images” to “mages”.
So the problem is this line in the function “reversePreparedOutput”.
(The function “reversePreparedOutput” tries to remove the media-source’s baseUrl from the TV value.)
But ltrim is the wrong function to use here. The second parameter is a list of all the characters to strip from the left side of the string: ltrim("assets/site/images/some_image.jpg","assets/site/") removes the i from images, because there is an i in the list. ltrim("assets/site/test–stuff/some_image.jpg","assets/site/") removes the t, e and s from test–stuff, because these characters are also in the list.