Evaluating Search and Replace Scanner: The Ultimate Tool for Drupal Bulk Content Edits?
June 29, 2024Drupal Odyssey is supported by it's readers. When you purchase products or services using the links on this site, we may earn a small commission at no additional cost to you. Learn more
It's 11:30 on a Friday morning and your manager sends you the following email.
John,
Legal has received the approved registered trademark paperwork for our Imaginary Program™
from the U.S. Patent Office. They have asked that all instances of the trademark symbol be
replaced with the registered trademark symbol [ ® ] across the entire site before the end of
the day.
I appreciate your prompt attention to this before the weekend.
--Beth
Bethany Clayton
Content Coordinator/Editor
Imaginary Company
http://www.imaginarycompany.io
(555) 555-5555
Wonderful! Our site has over 200 pages of content, not including image, pdf and video files, where this one freaking character could possibly be!
There's A Module For That
I recently ran into a similar scenario with a client, albeit, not this extreme in terms of timelines. I needed a solution that was easy to use and reliable. "Surely a tool exists already for this.", I said. I did a quick Google search for "drupal search and replace" and the first result was the Search and Replace Scanner module. Hmmmm … I'll give it a try.
What's In The Box
There's not much documentation for the module online, but I was able to get it installed and figure out how to configure it to get it "working" using the README file. I was surprised that in addition to Node entities, it also supported Paragraph entities out of the box. This was a major happy moment because the site I was working on used Paragraphs heavily.
After configuring the module, I ran a test scan and replacement on the site. It found 96 references of the trademark symbol in different fields on 68 different node and paragraph entities. Sweet!
But We're Missing Some Parts
I started browsing the site looking in places where I knew the trademark symbol was. {sigh} It didn't work. This is because the site uses Page Builder and has several custom blocks created with the core Block Content module. So I started looking through the source code and sure enough, there were plugins for Node and Paragraph entity types, but not the BlockContent entity type.
Fabricating A New Plugin
I was able to copy the Node plugin to a new BlockContent plugin and make some quick and dirty modifications where needed and got a functional BlockContent plugin. Then I reconfigured the module to account for the custom blocks and ran the scan and replacement again. It found an additional 36 references on 24 custom blocks. However, when examining the same previous pages as before, some of the trademark symbols had been replaced, but others were not. {fml}
I did some more searching and found an open issue that could be potentially causing the problem. Some of the custom blocks have Paragraphs (and sometimes nested Paragraphs). I'm currently working to help solve this issue and once I get my head wrapped around it, will post any code updates to the issue queue.
Other Content Entity Support
Not related to what I needed, but while looking at the source code, I noticed that the Term entity type did not have a plugin either. While it may be less common use case for taxonomy terms, they are used heavily and could contain content that needs to be replaced. In my mind, all of the basic core content entity types should have a plugin in the module code (i.e. Node, Term, BlockContent, Media, etc.). I may open some new feature request issues for these new plugins soon … at least the BlockContent plugin since I already have a working solution.
The Verdict?
While working with this module for a few hours, I can see its usefulness in the Drupal community. If you are not using the more advanced features of Drupal 9 and 10 and just use basic node fields and some paragraphs here and there, then this absolutely will work for the task. If you are using the more advanced features of Drupal, you'll need to find another tool or get involved with the project and contribute the missing pieces back to the community.
Have you used the Search and Replace Scanner module on a project successfully or implemented plugins for other content entity types? I'd love to hear your thoughts or comments on the module.
0 Comments
Login or Register to post comments.