I imported content from another system. So, for example, the body has typical html, like this:

<img src="/images/image.jpg />

All of the media assets that are referenced as static html, those files were already imported into Drupal and show up in the Files / Media tabs, so, using the WYSIWYG editor I can find that file and embed it and the Drupal link / entity reference for the same file looks like:


Is there a way to retroactively go through and replace all the static link references with their Drupal 8 entity reference equivalents, maybe by looking up the unique filename? Or is there a way to achieve this on initial import / re import?

I also need to do this for internal links.

  • 1
    It would be really hairy, but you could maybe do this with a batch process that iterates all nodes, uses DOMDocument to parse the (is it just a body field), look for img tags and grab the src attribute, look up the file entity by that src path - construct the HTML for drupal-entity tag, and replace that dom element with what you have above, convert back to string and then save it to the body field on the node. Or, there could be a module for this... I just don't know what to look for. – Kevin Apr 10 '19 at 21:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.