Submissions: "falsy" values not migrated. Default value tokens display wrongly

Created on 21 October 2022, about 2 years ago
Updated 15 April 2024, 7 months ago

Problem/Motivation

First, I noticed that certain webform submission data was not being migrated when I migrate them, specifically empty values for text fields.

Second, when a submission has an empty value for a field, and that field has a tokenized default value, such as [current-user:phone], that displays wrong when I view the submission.

Steps to reproduce

Regarding my first point, a change that I believe shouldn't have been made as-is was added in #3024586: The d7_webform_submission plugin must define the source_module property. β†’ . See commit

In D7WebformSubmission, it changed it to:

      if (!empty($item)) {
        $submitted_data[$destination_form_key] = $item;
      }

However, I think this is wrong, since empty() would then exclude values like these:

FALSE
0
"0"
0.0
""

https://www.designcise.com/web/tutorial/which-values-are-considered-fals...

I'm not sure if it's necessary to exclude NULL and [], or why that was added, but textboxes with empty string values, the value zero, and checkboxes with FALSE should all be allowed as values and migrated, I think.

About my second point, let me clarify using a text field with a default value of [current-user:phone] as the example:

  1. A user visits a D7 webform. They either clear out the [current-user:phone] phone number from the Phone field, or that user doesn't have a phone number.
  2. They submit the webform, leaving that Phone field empty.
  3. I migrate that webform submission from D7 => D9
  4. Then I visit the admin interface to view all submissions for that webform, or view the submission itself.
  5. Rather than seeing no value for that submitted field, I see the value of the [current-user:phone] for MY user account. So rather than seeing empty string, I see my own phone number.
  6. When I use Devel and view the submission, there is no value for that field at all. When I use Xdebug during migration, I see it skipping falsy values -- values that are "empty".
  7. If I do the same thing with a D9 webform, and submit an empty value instead of the token value, then view the submission, I see the configured element.empty_message set in webform.settings.yml, which defaults to {empty} (see WebformElementBase::build). Migrated empty values do not display this way.

I have not yet figured out why the default value is shown using the viewing admin's tokenized value, in this case, my own phone number instead of the submitted empty string.

Proposed resolution

I'm not entirely sure, but perhaps

if ($item !== NULL && !(is_array($item) && $item === [])) {

instead of

if (!empty($item)) {

I'm fairly certain that the values DO need to be migrated, as they could be used in queries with custom code, but missing values could cause problems.

And also some solution for the second issue I mentioned. I'm not sure why the values are being tokenized like that, but since the problem doesn't happen when I do it in D9, I think it's a migration issue.

Remaining tasks

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Fixed

Version

2.0

Component

Code

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024