When creating nodes in code, some fields should just be created as default, with its defaults subfields values as set in the Field UI. The multifield is not set, but is causing an database-error (see attached image).
What is the right way, to create a Multifield in code, with its default subfields values, set in the Field UI administration?
| Comment | File | Size | Author |
|---|---|---|---|
| #5 | 2198697-field-default-value-presave.patch | 4.36 KB | dave reid |
| #4 | 2198697-field-default-value-presave.patch | 1.6 KB | dave reid |
| error.png | 107.72 KB | sbilde |
Comments
Comment #1
dave reidIt might help me debug this for you if I can see what was in the $node object, and what code you're using to save the node programatically.
Comment #2
sbilde commentedThis is the function for saving the new imported node.
And this is the node-object just right before 'node_save', which creates the error:
Heres an image of the 'backend' for the node-fields, where each MultiFields is pointed out: http://d.pr/i/cC44
Comment #3
dave reidTo answer the first part of setting to default value, it looks like it should be automatically handled by field_default_insert. I'll investigate what happens when creating a node via code.
Comment #4
dave reidOk I think I have this narrowed down. Basically, I think this would be fixed by the core patch in #1899498: Field default values do not get hook_field_presave() run on them. Until that patch lands, however, I think we could work around for now. So let's try this patch.
Comment #5
dave reidWith a test as well!
Comment #6
dave reidConfirmed and committed #5 to 7.x-1.x. http://drupalcode.org/project/multifield.git/commit/e341e3c
Thank for helping report the bug in the first place!
Comment #7
sbilde commented5: 2198697-field-default-value-presave.patch queued for re-testing.
Comment #8
sbilde commentedYou are awesome Dave! - That patch did the trick. - Now I just have to go through it, and try to understand it :) - Thanks for your great effort!
Comment #10
dave reid