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:
- 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.
- They submit the webform, leaving that Phone field empty.
- I migrate that webform submission from D7 => D9
- Then I visit the admin interface to view all submissions for that webform, or view the submission itself.
- 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.
- 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".
- 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