If you have cck fields in node's created by feeds it wont pick up he default value for that field.

At first i was thought it was only the pollfield cck field: http://drupal.org/node/674004
But after seeing the same issue with other modules i tested it with a plain text cck field. It has the same behavior. Not picking up the default value you set for it ending up with an empty field with node's created by feeds.

Best regards,

Sergio

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

alex_b’s picture

Could you find out where exactly CCK populates default values?

sergio_’s picture

its stored in the database in the table "content_node_field_instance" wich contains fieldname records like "field_test" for example. Then in that fieldname record there is an item "widget_settings" wich contains the settings in this style:

a:4:{s:4:"rows";i:5;s:4:"size";s:2:"60";s:13:"default_value";a:1:{i:0;a:2:{s:5:"value";s:7:"test123";s:14:"_error_element";s:42:"default_value_widget][field_test][0][value";}}s:17:"default_value_php";N;}

In this case "test123" is the default value. I don't know if cck has some api/commands to retrieve it code wise.

After you created a node cck usualy saves the data in the table "content_type_movie" (movie being the content type its used in) that contains a vid(?) primary, a nid(node id to link) and the cck fields used in the content type in his case "field_test_value"

alex_b’s picture

Sorry - wasn't clear enough. I meant where it populates the values, not stores them. So on which callback / hook does CCK populate default values on a node? I assume it happens somewhere beneath node_object_prepare() - correct? If so, default values should be present before mapping, but mapping overrides the default values. If not, I'd be curious as to where else default values are being populated.

drewish’s picture

I wonder if the default was added after the nodes were created. My recollection is in that case the default isn't stored until the node is edited and saved again.

jay-dee-ess’s picture

Does the patch here:
http://drupal.org/node/612060

Help with this issue?

alex_b’s picture

herd45’s picture

Has anyone found a workaround for this? I would like to create a content type that includes some fields that are imported by Feeds, and other fields that use CCK default values. My default values work fine for nodes that I create manually, however the default values do not appear for nodes that are created by Feeds.

Hanno’s picture

@herd45: this is another scenario than I thought of.

I become aware that there are two cases for default values:
1. mapped cck fields with empty source values should be set to a default value
2. not mapped fields, should also get a default value, your case.

Case 2 is only needed on feed item creation and not on feed item updates. Case 1 however need some special attention for feed item updates: if a feed item is updated and the source value becomes empty, the behavior should be that the target value should fall back to the default value.

To make case 2 happen, we should build a node with all the default values filled.
I think this is working in the node_import.module in node_import.inc. I am not sure about this, but I think there is at the moment a difference between the feeds module and the node_import module in the way nodes are created: feeds doesn't build a node form, but just saves a node, whereas node_import and first build a node form, with default values and with all modules able to hook (like the module automatic nodetitle) and then submit and validates the node.
Is this indeed the case, and if so, is this by design?

voxpelli’s picture

Version: 6.x-1.0-alpha10 » 6.x-1.0-beta4
Status: Active » Needs review
FileSize
1.73 KB

I'm attaching a patch which uses default values for all empty values. It should perhaps be optional.

CCK adds the default values to the form and not in a nodeapi_prepare function which is a bit odd. To solve all problems the CCK values should be added in a nodeapi_prepare function - something that CCK itself needs to do, but also such a major change that they probably can't change it in 2.x.

To solve all cases of default values a patch against FeedsNodeProcessor.inc would be needed that exposes a way to add default values that isn't added in a nodeapi_prepare function.

Hanno’s picture

voxpelli: great work.
This patch is a solution for mapped fields (case 1 in #8).

With the proposed patch I see probaly a conflict with #873198: Import multiple values to tag vocabulary. When we have multiple source fields and the first one is empty, I am afraid that the target field becomes incorrectly filled with the default value. What dou you think?

voxpelli’s picture

@Hanno: Might be that no default at all is inserted - have to check that out. But we shouldn't be rolling patches that are dependent on each other - right? So lets wait until one of them has been committed and then adjust the other one to accommodate those changes?

AntiNSA’s picture

I am having the exact problem as the first post in this thread... I see there is some sort of conflict going on between this and another patch? What am I supposed to do? I cant get inherit taxonomy to work to I am trying to set a default cck taxonomy value...

AntiNSA’s picture

ok I am really stupid. I assumed taxonomy would automatically be inheritted, and not that you have to set the mappings. Works great. Thanks. defualt values of cck fields are not inherited when left empty though.

Hanno’s picture

@voxpelli #873198: Import multiple values to tag vocabulary is now committed , so now we can test what will happen with multiple source fields and your patch #9

alex_b’s picture

Status: Needs review » Needs work

#10 is a good point. When andrewlevine and I were working on resetting mapping targets before mapping to them we were talking about a reset callback.

    foreach ($this->config['mappings'] as $mapping) {
      if (isset($targets[$mapping['target']]['real_target'])) {
        unset($target_item->{$targets[$mapping['target']]['real_target']});
      }
      elseif (isset($target_item->{$mapping['target']})) {
        unset($target_item->{$mapping['target']});
      }
    }

Could be:

    foreach ($this->config['mappings'] as $mapping) {
      if (isset($targets[$mapping['target']]['reset_callback'])) {
        $targets[$mapping['target']]['reset_callback']($mapping['target']);
      }
      elseif (isset($targets[$mapping['target']]['real_target'])) {
        unset($target_item->{$targets[$mapping['target']]['real_target']});
      }
      elseif (isset($target_item->{$mapping['target']})) {
        unset($target_item->{$mapping['target']});
      }
    }

that reset callback could be where mappers/content.inc populates defaults. It's kind of a second pass node_object_prepare() :P

minghui.yu’s picture

I applied patch in #9 and it does not seem to work.

I am using beta9.

After importing RSS feed, value for a content type (text area) is still empty, though I have specified default value for that field.

minghui.yu’s picture

Any time-line on when this will be fixed? (Case 2 in #8)

Thanks,

Vote_Sizing_Steve’s picture

I think this also effects computed fields not being generating.

manuj_78’s picture

Version: 6.x-1.0-beta4 » 6.x-1.0-beta9

subscribing

minghui.yu’s picture

New release (beta 10) does not cover this issue yet.

Any timeline for this issue?

Thanks,

voxpelli’s picture

If someone updates the patch to address the issues mentioned here then I'm sure it will get accepted. I unfortunately haven't had the time yet as I'm managing very many projects at once right now. As in many opensource projects I think there's no timeline for this - it happens when someone decides to do something about it - feel free to do so :)

sillygwailo’s picture

Version: 6.x-1.0-beta9 » 6.x-1.0-beta8
sillygwailo’s picture

Version: 6.x-1.0-beta8 » 6.x-1.0-beta10

Still true in Beta 10.

(I don't know what possessed me, in the previous comment, to change the version that this affects to a previous version. I really did mean to change it to the latest.)

hampshire’s picture

subscribing

uwe_a’s picture

subscribing

lolmaus’s picture

Subscribing

Bartezz’s picture

subscribing, not picking up default version on cck link fields either...

TommyK’s picture

Subscribing. Also, I'm happy to test any patches that get made.

twistor’s picture

Issue summary: View changes
Status: Needs work » Closed (outdated)