Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
On pages like this /admin/structure/webform/manage/WEBFORMID/results/submissions for some forms we can see the following:
Notice: Undefined variable: key in Drupal\webform\Plugin\WebformElement\WebformCompositeBase->formatHtmlItem()
I have inspected the code and found that $key might have not been defined.
The patch will be provided.
Comment | File | Size | Author |
---|---|---|---|
#9 | 3029942-9.patch | 646 bytes | jrockowitz |
| |||
#8 | webform-submissions-result-page-key-might-have-not-been-defined-3029942-6.patch | 1.18 KB | Ruslan Piskarov |
| |||
#2 | webform-submissions-result-page-key-might-have-not-been-defined-3029942-2.patch | 697 bytes | Ruslan Piskarov |
Comments
Comment #2
Ruslan PiskarovAttaching the patch. Thank you.
Comment #3
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedThanks for the patch.
Can you provide an example webform that replicates this issue? I am not sure how to trigger the problem.
Because the $lines was just looped-thru we need to make sure the last key exists. Please see the attached patch.
Comment #4
Ruslan PiskarovHello @jrockowitz.
Your patch will not work. It happens for not-required fields, and if $lines is empty. Since removing "
" happens outside of the loop - $key might have not been defined.
In my previous patch $key it is a new variable `$key = key($lines);`, not from the loop.
I will provide the additional screenshots for betting understanding.
With your patch still PHP notices because undefined $key.
Because $lines can be empty.
If also can add "if (!empty($lines)) {" but it is not necessary because foreach skips the empty arrays. So I am thinking the patch #2 the best for now.
Comment #5
Ruslan PiskarovComment #8
Ruslan PiskarovSorry if you are confused, in a hurry I made patches from the wrong place.
Providing the alternative patch, however still thinking the patch #2 the best for now.
Comment #9
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedI think the patch can be as simple as returning an empty string when the $lines are empty.
Please review the attached patch.
Comment #10
andrey.troeglazov CreditAttribution: andrey.troeglazov at DrupalJedi commentedHello,
I have checked the patch from comment #9, it works for me.
Marking as RTBC.
Comment #11
Ruslan PiskarovAgree with #9.
Comment #13
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commented