Problem/Motivation

WebformLikert webform component always expects default value to be associative array, where keys are questions and values are answers. In D7 version, it's allowed to have default as a string this, which means that this answer should be default for all available questions.

1) Current migration does not support default value in array format;
2) Current migration does not handle transition D7 grid string value -> D8 WebformLikert array value;

Expected yml:

test_element:
  '#type': webform_likert
  '#questions':
    '1': 'Which one?'
  '#answers':
    '1': 'First'
    '2': 'Second'
  '#default_value': 
    1: '1'

Steps to reproduce

Migrate a webform with grid element and default value.

Proposed resolution

1) Add array support for default value;
2) Prepare default values for WebformLikert component;

Remaining tasks

1) Wait until #3172139: Enable project testing, and add a kernel test and a source database and files fixture is landed;
2) Update the database fixture and tests;

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

Matroskeen created an issue. See original summary.

matroskeen’s picture

Status: Active » Needs work
StatusFileSize
new1.72 KB

Here is an initial patch. It was created on top of #3185234: Single quotes are not escaped properly for select element options and element names, so it won't apply. Leaving as NW for now.

HitchShock made their first commit to this issue’s fork.

hitchshock’s picture

Status: Needs work » Needs review
StatusFileSize
new52.5 KB
new10.03 KB

Not only the migration of the default value that is an issue, the options and questions are also not migrated correctly.

D7 values (options/questions) looks like this:
1|First\n\r2|Second\n\r3|Third
This is a required D7 structure: "safe_key|Some readable option"

In the result we have to receive the following array of the options/questions according to the webform component behaviour:

[
  1 => 'First',
  2 => 'Second',
  3 => 'Third',
]

But at the moment the result looks like this:

[
  0 => [1, 'First'],
  1 => [2, 'Second'],
  2 => [3, 'Third'],
]

As the result, the data migrated incorrectly:
Component settings
Component settings

Fixed the issue around default value/options/questions migration and updated the test data.

[@matroskeen] It will be good to update the title to
Default value/options/questions for WebformLikert webform element are not migrated properly

hitchshock’s picture

Also, fixed a similar issue for the migration of the Select and EMail components.

joelpittet’s picture

Status: Needs review » Reviewed & tested by the community

Though I got a notice while running the migrations to fix this issue, it worked great and solved the problem of the WebformLikeRt errors.

New notice was:
[warning] Undefined array key 1 D7Webform.php:991

joelpittet’s picture

Fixed that caveat by trimming the raw value to remove whitespace before and after the values.

joelpittet’s picture

Version: 8.x-1.x-dev » 2.0.x-dev

Using this with 2.x

joelpittet’s picture

Status: Reviewed & tested by the community » Needs work

Have one issue where the first column misses values (most of the time, I saw one numeric one migrate fine).

joelpittet changed the visibility of the branch 2.0.x to hidden.

joelpittet changed the visibility of the branch 8.x-1.x to hidden.

joelpittet’s picture

Status: Needs work » Reviewed & tested by the community

Back to RTBC, the problem I ran into was a separate issue, this MR doesn't affect submissions, I will create a separate issue for that.

  • ruslan piskarov committed 6761e1cc on 2.0.x
    Issue #3206913 by By HitchShock, Ruslan Piskarov, joelpittet: Default...
ruslan piskarov’s picture

Status: Reviewed & tested by the community » Fixed
joelpittet’s picture

Thanks for getting this in!

Status: Fixed » Closed (fixed)

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

hitchshock’s picture

@ruslan-piskarov
An interesting way to handle credits of the ticket...

ruslan piskarov’s picture

Hi @hitchshock, I am not sure what I did wrong. As I see you and @joelpittet were tagged.
It's strange that you weren't credited.
I'm going to see how I can fix this.

hitchshock’s picture

Thanks, that didn't ignore me ^_^