Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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.
Comments
Comment #1
Summit CreditAttribution: Summit commentedHi, could you attach your plugin please?
Thanks à lot in advance!
Greetings, Martijn
Comment #2
valderama CreditAttribution: valderama commentedoh seems like i forgot to attach it last time. here is the zip..
Comment #3
michaelfavia CreditAttribution: michaelfavia commentedThis patch applies cleanly to 7.x-1.x and adds an "Only if empty checkbox". It also adds rudimentary token replacement.
Comment #4
michaelfavia CreditAttribution: michaelfavia commentedsorry for bugspam.
Comment #5
GaborTorok CreditAttribution: GaborTorok commentedI 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.
Comment #6
GaborTorok CreditAttribution: GaborTorok commentedThe 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.
Comment #7
GaborTorok CreditAttribution: GaborTorok commentedToken replacement is same as rewrite, so not minimal
Comment #8
chrowe CreditAttribution: chrowe commentedNot 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.
Comment #9
chrowe CreditAttribution: chrowe commentedI 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!
Comment #10
queenvictoria CreditAttribution: queenvictoria commentedPatch 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
Comment #11
twistor CreditAttribution: twistor commentedToken replacement is a whole different thing and shouldn't be done here.
Comment #12
chrowe CreditAttribution: chrowe commented@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.
Comment #13
imperator_99 CreditAttribution: imperator_99 commentedHi 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.
Comment #14
mradcliffeThe 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.
Comment #15
twistor CreditAttribution: twistor commentedThis should address the concerns involved.
Comment #16
twistor CreditAttribution: twistor commentedbahhh.
Comment #19
twistor CreditAttribution: twistor commentedComment #21
RgnYLDZ CreditAttribution: RgnYLDZ commentedHi, 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?