I have textarea fields in my headless drupal 8 site. When I get the node via REST in json it does not give the domain name in the image urls that are uploaded via ckeditor. So the images are not shown when I display this field.

2 Answers 2


You can relatively easily fix the images on the client using jQuery by following Correct Img Src Path with Javascript and Jquery.

  • Thanks, I actually already did something similar in the mean time. But it feels hackish and not like a proper solution.
    – Catorghans
    Mar 5, 2016 at 13:47
  • Using embedded images in fields in a headless context is probably not wise as you have no control on image size either. I prefer image fields as ie my angular can either fetch the images or add an image style to them depending on device. btw please + vote my answer :p Mar 5, 2016 at 13:51
  • That's the worst approach you can consider.
    – otarza
    Mar 5, 2016 at 14:06
  • @otarza please elaborate on that. Mar 5, 2016 at 14:47
  • You suggested replacing all image sources on client side, which is just not good idea for many reasons. On the other hand this approach requires to replace sources on every client using the service. Service should provide correct urls to images and its not clients job to determine where is image, it should just render. Anyway solving this on server is simple and will prevent any further problems.
    – otarza
    Mar 5, 2016 at 15:16

CKEditor uses relative urls and that's right, because if service URL changes for some reason urls must not be hardcoded, otherwise image urls will become invalid.

You can impement hook_entity_load() and edit your field's value using regular expression.


To prevent hardcoding of website's url, you can use $base_url global in hook_entity_load.

  • That would contradict you "urls must not be hardcoded" and the fix is only needed for REST. It probably breaks CK Editor later on when configured to only accept relative path too. Mar 5, 2016 at 13:47
  • No that's not true. $base_url global can be used in hook_entity_load to prevent hardcoding.
    – otarza
    Mar 5, 2016 at 14:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.