Hey,

When submitting a webform that contains a commerce_webform component the value for any addressfield (in webform submissions) is removed. It looks like this is because addressfield_tokens unserializes the address in hook_webform_submission_load().

According to this comment from #1523364: How do I save array (checkbox) values in a custom component?:

Use _webform_submit_[component_name]() in your custom component. See how the date, time, and file components convert the data from arrays into string values in their submit functions.

Looking at those components it seems you should unserialize the data in the appropriate component display hook (eg. see _webform_display_date(), _webform_table_date() etc.).

It might be related to #1828426: Notice: unserialize() [function.unserialize]: Error at offset 0 of 5 bytes and #2614470: Can't change country when editing a webform submission but I haven't checked.

Comments

bezlash@gmail.com created an issue. See original summary.

andyf’s picture

Title: Address field submissions » Don't unserialize address in hook_webform_submission_load()
Project: Commerce Webform » Addressfield Tokens
Version: 7.x-2.x-dev » 7.x-1.x-dev
Issue summary: View changes
andyf’s picture

Status: Active » Needs review
StatusFileSize
new5.27 KB

Thanks!

rmcom’s picture

Priority: Normal » Major
Status: Needs review » Patch (to be ported)

This patch is important and works well with 7.x-1.6.

Please add it to the next version.

andyf’s picture

Priority: Major » Normal
Status: Patch (to be ported) » Needs review

@rmcom Thanks for confirming it works for you; if one or two others do the same we can mark it as Reviewed & tested by the community. Just so you know, the status Path (to be ported) is for patches that need to be ported to a different major version of Drupal.

lambic’s picture

This patch doesn't look right to me, why is the hook_webform_submission_load implementation being removed?

lambic’s picture

Status: Needs review » Needs work
andyf’s picture

Status: Needs work » Needs review

@lambic Thanks for taking a look.

I've forgotten some of the specifics now, but the summary I think basically describes the problem. I was investigating an issue with vanishing address values in a webform and couldn't find any explicit documentation for how to implement multi-value webform components (IIRC) but I found the linked issue with a comment from quicksketch. He suggested using the date/file modules as examples. They take a scalar value in the component display hook and then create the necessary render array; there are two examples in the summary, and also see also _webform_display_file().

So my understanding was/is hook_webform_submission_load() is the wrong place for deserializing which is why it's gone. The bug only manifested when used with commerce_webform but the solution seemed to be to update addressfield_tokens. Sorry I can't remember more about it now.

rmcom’s picture

Priority: Normal » Major
Status: Needs review » Reviewed & tested by the community

Would it please be possible to integrate this into the next release. Until this is done, each update generates a major problem for each site using commerce_webform (which is the case for currently over 1,150 websites)?

Thank you so much!!

When the changes by AndyF are applied, the issue disappears while, at the same time, none of the functionality of this great module is lost.

lambic’s picture

Patch doesn't apply currently, looks like it needs a reroll.

hass’s picture

Status: Reviewed & tested by the community » Needs work
tmai82’s picture

Please implement this patch, every update breaks our online registration system that uses webform commerce. This patch addresses the issue and fixes it, but it's tiring to redo it every time there is an update.

rmcom’s picture

Version: 7.x-1.x-dev » 7.x-1.8
Status: Needs work » Patch (to be ported)
StatusFileSize
new5.91 KB

Attached please find the patch to fix this issue.

This patch also makes this module compatible with Webform 7.4 by:

- '#required' => $component['mandatory'],
+ '#required' => $component['required'],

  • lambic committed 4105cf9 on 7.x-1.x authored by rmcom
    Issue #2674752 by AndyF, rmcom: Don't unserialize address in...
lambic’s picture

Thanks for the new patch, it has been applied in the 7.x-1.x branch.

lambic’s picture

Status: Patch (to be ported) » Fixed

Status: Fixed » Closed (fixed)

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