This module allows you to directly search for and replace text within your Drupal database, targeting specific entity fields. It's designed to handle large datasets by processing operations in batches and provides options to limit your searches by entity, bundle, field, and data type. This is useful for tasks like updating URLs, rewriting file paths, or standardizing text across your site.
Entity Search & Replace finds a string in the text fields of your entities, counts where it appears, and replaces it. It comes as two modules:
- Search and Replace (
snr) rewrites the field tables directly with SQLREPLACE(), in the current and revision tables. It creates no revisions and cannot be undone. - Safe Search and Replace (
snr_safe) loads each matching entity and saves it as a new revision with a log message. Earlier revisions keep the old text, entity hooks run as usual, and entities the user may not update are skipped.
Use cases
- Changing absolute URLs to relative URLs
- Updating file paths after moving a directory
- Pointing links at an old domain to a new one
- Finding how often and where a problem string appears (for example, pasted Microsoft Word styling)
- Changing strings to fit a consistent pattern
How it works
- The form lists the text columns of every stored field: titles, bodies, summaries, link URIs, email addresses, image alt text. IDs, formats, numbers, serialized columns and password hashes are not offered.
- Filter the list by entity type, bundle, field, column or type.
- Search counts the matching rows or entities and changes nothing. Matching is case-sensitive and literal.
- Replace lists the targets, shows a backup warning, and runs as a batch only after you confirm.
Stability and safety
Search and Replace writes directly to the database. Back up the database before every replace and run Search first. Use Safe Search and Replace for content that editors maintain, so every change can be reverted from the revision history.
Releases up to 1.0.1 inserted the search text into SQL without escaping, so quotes and semicolons broke the query, and Safe Search and Replace could not be installed on Drupal 10 or 11. Update to the latest release and run drush updb. Both forms now need their own restricted permission, which the update grants to roles that had Administer site configuration.
Automated tests cover both modules on Drupal 10.5 and 11.4, and the update from 1.0.1 was tested on Drupal 9.5 and 10.5.
Requirements
- Drupal 10.3 or later, or Drupal 11.
- Entity types stored in SQL tables (core's default storage). Safe Search and Replace works on revisionable entity types.
Documentation
Installation, permissions, usage and troubleshooting: project.pages.drupalcode.org/snr.
How this module is built
Changes to this module since 2026 were drafted with an AI coding assistant (Claude Code). The maintainers review, test and take responsibility for every change, and the tests and code checks run on drupal.org's CI. Contributions follow Drupal's policy on the use of AI when contributing.
Supporting this module
Developed and maintained by Tyler Brown Cifu Shuster and Jason P. Salter of FivePaths, LLC. Development sponsored by FivePaths.
Ask your assistant about Entity Search & Replace
Check compatibility with your Drupal and PHP version, maintenance and security coverage, from current release data. How it works
Depends on
Dependencies of the latest stable release
No dependencies recorded for this project.
Required by
Tracked projects that depend on this one
No tracked projects depend on this one yet.