When editing an image TV in FRED, it insists on adding the full path the the image in front of the image path, regardless of what media source is assigned to the image. So, for example, and image TV set to the “Images” media source, with the path “assets/images”, is saved correctly when edited in MODX as:
I tried setting the image inside the page template both with and without data-fred-name="page-image" data-fred-target="tv_pageimagenew", and it made no difference.
The “Images” media source is enabled for FRED, the image TV has the “Images” media source assigned to it, and TV Properties has fred.mediaSource set to “Images” and fred.type set to “image”.
Yes, but the code change from the old forum topic (that resolved the issue) was never acutally changed in the Fred source code.
Does it fix this issue, if you apply the same code change again (to this new version of Fred)?
So it looks like the same functionality (removing the path of the media-source from the TV value) is now executed in this function (same function name but different file):
(I tried to test it (locally on Windows), but with paths in Windows (and MODX in a subfolder) the whole function code breaks anyway).
Do you get this error in the MODX error log? → Could not load class: modFileMediaSource from mysql.modfilemediasource.
If not, log the values of $url and $value after line 438 to help to figure out why the media-source-path doesn’t get removed:
If I put it after the line that sets $url, nothing gets recorded, because the script doesn’t get that far. This lines that set the URL are inside this:
if ($this->modx->loadClass($classKey)) {
which fails because the modFileMediaSource class can’t be loaded.
Well, that partially fixes the problem. It doesn’t endlessly add the source path over and over again when saving, creating longer and longer strings each time. But, it still adds the media source path to the image. So, since the image is defined to use the “Images” media source, it should get saved in the DB as “test-stuff/inside-sample-2024.png”, but it’s getting saved as “/assets/site/images/test-stuff/inside-sample-2024.png”. And, note that it is adding an initial slash as well, which is not in the media source definition for the path (“assets/site/images”).
So when you select a new value for the image TV in the front-end and then click “Save”, what are the current values that get logged (for $url and $value)?
FRED is adding a leading slash to the TV path ($value), so “substr($value, 0, strlen($url))” does NOT match “$url”, and the truncated string does not get saved.
So the question is, where is FRED adding this initial slash?
Adding this at the top of the function fixes the issue: if(substr($value, 0, 1) == '/') $value = substr($value, 1);
Spoke too soon. The first time I select an image TV and save it, the correct path gets saved. But for all subsequent page saves, the media source path gets added. That’s with your suggestion of adding this: $url = $this->modx->getOption('base_url', null, MODX_BASE_URL) . $url;
When I use my fix: if(substr($value, 0, 1) == '/') $value = substr($value, 1);
then the correct path gets saved, even on subsequent saves.