I am pulling 2 cvs files from 'supplierA' and 'supplierB'. And I have setup 2 feeds imports for them.

On import-A, I want to set a static default value for a 'supplier' field, so that entities created by import-A will have the supplier field set to 'supplierA'. And the same for import-B and supplierB.

But the original cvs files do not have the 'supplier' field. How do I ADD a tamper plugin/rule for a field that does not exist in the source cvs file?
I tried to add a mapping rule source: {empty string} target: 'supplier'. But Tamper module uses the source name as the id for the import plugin/rule so obviously that didn't work.

Any idea?

Comments

jzornig’s picture

I also want to do this.

jzornig’s picture

I can use an existing field from the source that I was not needing and overwrite it's value with the default I want. But I can't make up a field name that doesn't appear in the source.

leex’s picture

I would also like to do this. I tried using the 'set default value' plugin but none of the plugins execute if the source field doesn't exist.

leex’s picture

I can see there is a 'blank source' option when you are importing an RSS feed, but not a CSV. This is all we would need to solve the problem:

http://drupal.org/node/1406210

Just look at the description here:

Blank source 1 A source provided by Feeds Tamper with no value of it's own.

Exactly what I want!

jzornig’s picture

leex, thanks for that tip. I was actually already using feeds tamper but had not seen the blank source feature.

leex’s picture

I guess you're not importing a CSV file then. Lucky you can use the feature.

dalearyous’s picture

i would also like to do this with a csv file!

jzornig’s picture

yes, I was importing from an ldap query.

mindaugasd’s picture

I am also looking for some solution here.

Anonymous’s picture

I'm using for this "Find replace REGEX", with "REGEX to find" -> "/^\s*$/" and the replacement pattern you need.

mortona2k’s picture

I'm going to tamper an existing field to make it work, but I think this feature should exist since the workaround is not intuitive.

EDIT:
Hmmm, can't seem to get this to work. I just need the value "US", so I put that in the replacement pattern (with no quotes), but that doesn't work. Can you please explain a little further?

jonmcl’s picture

@mortona2k (any anyone else):

I think that because the column doesn't actually exist, Tamper never gets a chance to run is plugins. I tried both "Rewrite" and "Default value" plugins and neither was able to populate the field.

I ended up using Feeds' hook_feeds_presave function:

function clc_affiliates_feeds_presave(FeedsSource $source, $entity, $item) {
  if ($entity->type == 'affiliate') {
    $entity->field_affiliate_address[LANGUAGE_NONE][0]['country'] = 'US';
  }
}

(obviously this code is specific to the site I'm working on)

mortona2k’s picture

JonMcL, I ended up with that as well. Would be a great feature, so we could do everything within tamper.

agileadam’s picture

#12 worked well for me also. Thanks JonMcL!

fureigh’s picture

Another approach is to set up your own dummy field in the import mapping, if you have an unneeded source field to spare. You can do something like this:

0 -> Title (example)
1 -> Name (example)
17 -> Field For Which You Want To Set a Default Value

Then use the Feeds Tamper UI to add the 'Rewrite' plugin to the second '0', and specify the value you want.

However: if you try to use an existing field (like 0 or 1) again, Feeds Tamper will only let you rewrite all instances of the field at once.

blanca.esqueda’s picture

I had a similar situation where if a value was empty then another field value needed to be used.
I created a path for the rewrite plugin as it has the flexibility not only to use a replacement patterns but as well a custom strings, or a mix of both.

http://www.drupal.org/node/2632056

nwom’s picture

Title: how to set a default value if field does not existing in source » Allow setting Default Value from Blank Source
Version: 7.x-1.0-beta3 » 7.x-1.x-dev
Component: User interface » Code
Category: Support request » Feature request

Changed the title to better match the issue. Setting a default value from a blank source is not possible, and instead as a work-around a dummy source must be used (and then overwritten). I would love the ability to no longer need to depend on a dummy source.

Thanks in advanced.

nwom’s picture

#16 is not a workaround for this issue sadly, but instead fixes a different problem.

blanca.esqueda’s picture

#15 works!!!
Map a dummy field, --- the content assigned initially doesn't matter, it can contain the value of any other field ---
And then use the rewrite tamper plugin to replace with the needed value.
But as @fureigh commented make sure that it is a separate source for this to work as expected.

I think that the ability to no longer need to depend on a dummy source for this cases has to be set up on the feeds module and not the tamper module. Feeds module is the one that manage the fields mapping.