- Issue created by @fago
- First commit to issue fork.
- 🇸🇮Slovenia useernamee Ljubljana
So I had file_base_url service injected into the decorated file url generated but then I've noticed that it already has absolute file url generation method and I hope this one will suffice.
- Assigned to fago
- Status changed to Needs review
about 2 years ago 4:00pm 4 March 2023 - @fago opened merge request.
- Status changed to Needs work
about 2 years ago 2:16pm 7 March 2023 - 🇦🇹Austria fago Vienna
reviewed the MR and added a couple of remarks. Main part is we should make sure to only do this when serving /ce-api responses:
> Serving files and images using absolute URLs keeps the file URLs working in a decoupled frontend. When disabled, care must be taken to resolve URLs otherwise.
- 🇦🇹Austria fago Vienna
> Main part is we should make sure to only do this when serving /ce-api responses:
This can be checked by getting current request and doing:
$is_api_response = $processed_request->attributes->get('lupus_ce_renderer') || $processed_request->getRequestFormat() == 'custom_elements';
- First commit to issue fork.
- 🇦🇹Austria fago Vienna
thx, changes look all good now, but I don't see it working. Does it work for you?
"content": "\n <div class=\"wide-image primary-image field field--name-field-image field--type-image field--label-hidden field__item\"> <img loading=\"lazy\" src=\"/sites/default/files/styles/wide/public/2023-03/continental.jpg?itok=_N-3d5Sh\" width=\"676\" height=\"489\" alt=\"dsafasdf\" />\n\n\n</div>\n "
Maybe the API-response is not detected? your way of doing it seems ok, but maybe it's not ? else use;:
$is_api_response = $processed_request->attributes->get('lupus_ce_renderer') || $processed_request->getRequestFormat() == 'custom_elements';
- 🇷🇸Serbia petar_basic
I've tried with
$is_api_response = $processed_request->attributes->get('lupus_ce_renderer') || $processed_request->getRequestFormat() == 'custom_elements';
but it still does not work.
Needs more debugging to see why it is not set. - 🇦🇹Austria fago Vienna
we must override both generateString() and generate() to return the absolute URL, see the working example of CDN module's \Drupal\cdn\File\FileUrlGenerator - then it should start working.
- 🇷🇸Serbia petar_basic
I've overrided the generate method now as well. Also moved the common code into the separate helper function.
Tested locally and on drupal pod, works well for me now.
"content":"\n <div class=\"wide-image primary-image field field--name-field-image field--type-image field--label-hidden field__item\" <img loading=\u0022lazy\u0022 src=\"https:\/\/8080-shaal-drupalpod-k6ot9a4erhh.ws-eu89b.gitpod.io\/sites\/default\/files\/styles\/wide\/public\/2023-03\/Screenshot%20from%202022-12-06%2009-59-05.png?itok=C9VjS8XY\" width=\u0022589\u0022 height=\"583\" alt=\"test\" ></div> "},
- Status changed to Fixed
about 2 years ago 8:55am 9 March 2023 Automatically closed - issue fixed for 2 weeks with no activity.