Using preg_match_all(), str_replace() and strpos() for processing HTML is not the best way because its poor performance, especially not in Drupal 8, where Symfony's DomCrawler library is available.

I wrote a custom migration before which also needed to fix inline images and internal links in important content and I used DomCrawler that is why I'm suggesting it, because I know it will work.

Comments

mxr576 created an issue. See original summary.

greg.1.anderson’s picture

Sounds like a good idea -- I should probably be preprocessing the html with tidy anyway, probably (either before sending it in via migrate csv, or with a separate process plugin).

Would you happen to still have any of that code?

bradjones1’s picture

Status: Active » Needs review
StatusFileSize
new12.18 KB

Here's a WIP but mostly-working patch that supports using Symfony Crawler and also fetching images from a remote URL, which was my use case. I would appreciate testing in the original use case, where the file entities already exist. I think we could also support a condition where the file exists on the local disk but needs a File entity created to store it in Drupal?

bradjones1’s picture

StatusFileSize
new12.18 KB
new269 bytes

Migrate is in core... fix dependency.

greg.1.anderson’s picture

I'm not doing any site migrations at the moment, and don't have any planned in the near future. Would you like me to add you as a maintainer for this project, @bradjones1?

bradjones1’s picture

Sure, thanks.

greg.1.anderson’s picture

Done. Thanks for helping out here.

bradjones1’s picture

Cool, thanks.

  • bradjones1 committed 26fd188 on 8.x-1.x
    Issue #2868622 by bradjones1: Use DomCrawler for processing field value
    
bradjones1’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.