Hello,

I recently was working on a project that needed Search and Replace functionality on node fields through VBO. The modify node fields wasn't quite enough because that only allowed the user to change the entire value of a field rather than just a part of it. I created a module to define the action and it works pretty well. I was going to post the module as a project, but felt that I should check here to see if you would be willing to integrate a search and replace action into VBO. I think it would be better to integrate it rather than throw another module into the mix. I've attached the action which is properly formatted for quick integration. You should be able to just drop the file into the views_bulk_operations module root and give it a test.

Here are some of the features:

  • Configuration options on the VBO views config page to choose field selection widget and to exclude certain fields (just like modify node fields)
  • Field list for search and replace is dynamically generated to only offer fields that are available in the currently selected node (also, just like modify node fields)
  • Users can search one or some or all of the fields at a time
  • Support for search prefixes and suffixes to create advanced searches
  • Options for case sensitivity and exact matches

Thanks for your time!

Comments

drclaw’s picture

StatusFileSize
new3.7 KB

Sorry left a couple dpms in there! Here's a better file.

giorgio79’s picture

Fantastic. This could replace the Search and Replace Scanner module: http://drupal.org/project/scanner

Can this action do regular expression search and replace as well?

drclaw’s picture

Not yet, but that could easily be built into it, I think...

giorgio79’s picture

infojunkie’s picture

Can someone please review this action and post feedback?

giorgio79’s picture

Status: Needs review » Needs work

Just tested it, it is pretty good.

Few issues:
1. Noticed a dpm line here
Called from /sites/all/modules/views_bulk_operations/search_and_replace.action.inc, line 21

2. Also noticed, that only CCK fields are offered for selection, would be great to have node title and body as well in the fields list.

drclaw’s picture

Glad to see someone is interested in this!

I'm a bit of a dpm bandit, sorry about that. =P

Getting the title and body in there should be no problem, and I agree that it would be useful. I'll take a look at that and post a new patch soon

infojunkie’s picture

@drclaw: if you plan to add support for non-CCK fields, I suggest you take a look at fields.action.inc because it uses a generic hook mechanism to handle arbitrary fields. You could use the same hook and augment it with information you need.

drclaw’s picture

@infojunkie I actually used that action as a starting point but left that part out. I'll revisit it and see what I can do.

marcusx’s picture

cool stuff +1 from me

marcusx’s picture

Will this work for the D7 Version of VBO as well? I tried it, and I got no error but I also get no search and replace action in the vbo configuration either.

bojanz’s picture

No. This code uses CCK, so it would need to be rewritten for D7 (and Field API).
Same reason why the D7 version of VBO still doesn't have the action to bulk modify fields, see #1057158: Provide an action for modifying entity values.

salah1’s picture

drclaw,
How do you recommend for the code to be used meantime?
I'm new to Drupal and my only thinking is i put this into module and provide form for it to be used?
How should i test this in drupal site?

drclaw’s picture

StatusFileSize
new4.36 KB

I'm attaching the action again, this time with support for the title and body fields. I don't know how much time I will have in the next little while to support all arbitrary fields, but hopefully this helps some people out for now.

@m-abshir:

Download the file, and unzip it.

  • Put the file in the views_bulk_operations module folder
  • Create a view and a "Page" display and choose views bulk operation as the "Style"
  • In the settings for the Views bulk Operations style, scroll to the bottom and check "Search and Replace" within the "Selected Operations" section
  • There is also a fieldset called "Search and Replace" at the bottom of the settings page. Expand it and there are additional settings
  • Add whatever fields you want to your view and save it.
  • Go to the view's page and test the new action
  • infojunkie’s picture

    Status: Needs work » Needs review
    bojanz’s picture

    Status: Needs review » Closed (won't fix)

    Nice work!
    However, I think this action should live in its own module. That would give you direct access to improve it, and a faster way to provide support (as well as a D7 port).
    My idea is to have only the most needed core actions in VBO, especially since the D6 branch is basically in maintenance mode.

    drclaw’s picture

    Okay, cool. Thanks for the info. I'll put it in a module. Just thought I'd check here first. =)

    Thanks!

    adam_b’s picture

    subscribe

    jenlampton’s picture

    @drclaw would you please add a link to your module in this issue queue? :)

    drclaw’s picture

    Sorry @jenlampton, I never created a module for it. =/

    I'll get started on that ASAP and post a link here.

    drclaw’s picture

    In case anyone is interested, I finally made a project for the vbo search and replace module. There's a D6 and D7 version. I just made a couple of dev releases but they're pretty stable. Some testing would be great so I can put out a full release. =)