Actually I thought that the existing default value plugin works like this. In fact, it always sets the field to a predefined value, even if the field has a value already.

I needed a plugin, which only sets the value, if the actual field is empty. I called it empty_default_value for now.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Summit’s picture

Hi, could you attach your plugin please?
Thanks à lot in advance!
Greetings, Martijn

valderama’s picture

FileSize
540 bytes

oh seems like i forgot to attach it last time. here is the zip..

michaelfavia’s picture

This patch applies cleanly to 7.x-1.x and adds an "Only if empty checkbox". It also adds rudimentary token replacement.

michaelfavia’s picture

Status: Active » Needs review

sorry for bugspam.

GaborTorok’s picture

Title: New Plugin: Set a default value, only if a field is empty » Default value plugin: Option to set the value only when field is empty and provide minimal token replacement
Version: 7.x-1.0-beta3 » 7.x-1.x-dev
FileSize
1.83 KB

I really need these functions for my project, so I'm glad that you provided a solution.

I made all code in feeds_tamper_default_value_callback() conditional, because the unconditionally executed part only prepared values for the conditionally executed part.
I rerolled the patch for the current 7.x-1.x branch. Currently, there are two "$source"-s in the argument list instead of one "$result" and one "$source" since this commit: http://drupalcode.org/project/feeds_tamper.git/commit/6ce94be9041d48b2b9..., and this may be a bug and will need a separate issue.
I think the token replacement would normally need a separate issue to not to mix separate things in a single patch, but that would complicate things, so I left that as it is.
Modified the issue title to reflect changes.

GaborTorok’s picture

The previous patch doesn't work with the new function signature, sorry for not testing. It seems that the first argument should have been named $result, but it was named $source, and it only presented a problem, when this patch used it and introduced the last parameter, that is also called $source.
There was also a problem with source field name case with the CSV parser.
I corrected the function signature, copied the config form arrangement and CSV handling from the Rewrite plugin and removed the question mark and trailing tab character from the "Only if empty" title. Now the only difference between the Default value plugin and the Rewrite plugin is the "Only if empty" functionality.

GaborTorok’s picture

Title: Default value plugin: Option to set the value only when field is empty and provide minimal token replacement » Default value plugin: Option to set the value only when field is empty and provide token replacement

Token replacement is same as rewrite, so not minimal

chrowe’s picture

Not working for me

Drupal-7.15
Feeds-7.x-2.0-alpha7+33-dev
Feeds Tamper-7.x-1.0-beta3+55-dev
Applied patch in #6

Importing Taxonomy Terms and some term names are empty. I see the check box and I check it. The setting seems to be saved but terms without names are getting skipped instead of having the default value applied.

chrowe’s picture

I found a workaround for this.

I used the Feeds Tamper "Find replace REGEX" plugin to search for a blank field
/^\s*$/

the / at the begining and end are required by the plugin, so any regex expression you want to use can go between them.

This should find a blank field or any number of spaces.
I found this expression at http://stackoverflow.com/questions/3012788/regex-check-if-a-line-is-blan...
I also found this expression tester helpful http://www.regular-expressions.info/javascriptexample.html

Then just put your 'default value' in the "Replacement pattern" field as plain text, and presto!

queenvictoria’s picture

Patch in #6 works for me. @chrowe what failed for you?

Drupal 7.22
Feeds 7.x-2.0-alpha8
Feeds Tamper 7.x-1.0-beta3+56-dev

twistor’s picture

Title: Default value plugin: Option to set the value only when field is empty and provide token replacement » Default value plugin: Option to set the value only when field is empty.
Status: Needs review » Needs work

Token replacement is a whole different thing and shouldn't be done here.

chrowe’s picture

@queenvictoria

Edit: Now I see my post where I did actually try the patch and described what happened.
"Importing Taxonomy Terms and some term names are empty. I see the check box and I check it. The setting seems to be saved but terms without names are getting skipped instead of having the default value applied."

Not sure how to describe my issue better as I did not troubleshoot much.

imperator_99’s picture

Hi all,

Patch in #6 is not working well for me either. I get an unhelpful "Notice: Undefined index: only_if_empty in feeds_tamper_default_value_callback() (line 62 of /.../modules/feeds_tamper/plugins/default_value.inc)".

I get this error for each of my feeds (of which there around two dozen) so it is not limited to some incorrect setting on one particular feed.

Anyone else get this?

Cheers,
Jesse.

mradcliffe’s picture

The patch in #1870842: Default value overwriting values from feed worked for me, which was a one line fix. That issue was filed as a duplicate a while ago.

I am waiting on this issue before I can update Feeds Tamper otherwise Feeds is useless to me. I consider this critical and haven't updated Feeds Tamper in over a year because of it.

twistor’s picture

Issue summary: View changes
Status: Needs work » Needs review
FileSize
2.19 KB

This should address the concerns involved.

twistor’s picture

The last submitted patch, 15: feeds_tamper-default-value-1447920-15.patch, failed testing.

  • twistor committed a50a30f on 7.x-1.x
    Issue #1447920 by GaborTorok, twistor, michaelfavia, valderama: Default...
twistor’s picture

Category: Feature request » Bug report
Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

RgnYLDZ’s picture

Hi, it seems that this patch is commited to both dev and stable release. But I can't see any "Only if empty" option in rewrite plugin. Where and how does this work exactly?