I don't know if this is a feature request for the existing 'Find Replace' plugin or if an aditional plugin should be written, but basically it's just to enable the use of Tokens in the find field, like in the 'Rewrite' plugin.

My use case is that a source field mapped to a node Title includes certain words I'd like to strip out, especially if they exist in another source field I could reference through a token. The reason I need this is that I don't have prior knowledge of the exact words I'd like to strip out.

For example, given the following sources:
Description: 'Nike Crosstrainers for Men size 8'
Brand: 'Nike'
Size: '8'

I'd like to map the Description to the node Title and end with only 'Crosstrainers for Men' using a couple of tamper 'Find Replace' plugins like so:
Find: '[Brand] '
Find: ' size [Size]'
and replace them with an empty string.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

ts145nera’s picture

Hello,
I've similar problem, so I have done this patch to enable tokens in "find replace".
The idea is simple, after enable "Use token" in "find replace" function you can use the same tokens in "Rewrite" function.

Case:
I've product description and I would insert product name in the description
I can insert wildcard "#" in the description
Using "find replace" now I can replace # with [name]
during the import [name] will be replaced from "name" field

I hope this is usefull

elpino’s picture

Thanks a lot, the client decided not to change the titles so I can't test it just yet, but as soon as I can I will.

If anyone else finds it useful test it out, then maybe we can get the patch submitted.

Daniel Wentsch’s picture

Thanks for the patch, worked nicely for my requirements :)

twistor’s picture

Status: Active » Postponed (maintainer needs more info)

How does this do anything when the tokens are replaced after the find/replace?

geoffreyr’s picture

Here's the use case that I used this patch for: I needed to import a bunch of blog posts from a HTML page, and in the process of doing so, rewrite any image links that pointed to the local server to complete URLs. I would be using temporary targets to extract URLs from other elements in the blog post, and would clean them up along the way.

The effective intended behaviour was as follows:
replace src="/blogname/path/to/image.jpg" with src="http://example.com/blogname/path/to/image.jpg", and
replace src="./path/to/image.jpg" with src="http://example.com/blogname/path/to/image.jpg"

I tried a number of different things within Feeds Tamper, but I couldn't see any way to enable the token replacement behaviour twistor described. It would just output src="[xpathparser:7]/blogname/path/to/image.jpg" into my HTML.

I've put together and attached an updated version of ts145nera's patch. Along with the original behaviour, this adds support for recursive array values, in order to avoid any pesky array to string conversion values. (It might also make sense to add some way to generate a straightforward string version of the array, concatenated by some delimiter or other. What do you think?)

geoffreyr’s picture

FileSize
1.89 KB

Updated this again to gracefully handle old versions of find_replace plugin config that doesn't contain use_token.

flashwebcenter’s picture

The patch worked fine with my case. I am migrating some content and some of the titles have the two letters NA. I used find and replace with some tokens from rewrite function.