Problem/Motivation
Not all webform fields show up under admin/config/sharepoint_connector/settings/webforms/configure?id=[webform title]&machine=[webform id]
Steps to reproduce
- Create a new webform; /admin/structure/webform/add
- Name it whatever you want; "hierarchy 1"
- Add in nested elements;
checkbox1:
'#type': checkbox
'#title': checkbox1
flexbox1:
'#type': flexbox
textarea1:
'#type': textarea
'#title': textarea1
page1:
'#type': wizard_page
'#title': page1
textarea2:
'#type': textarea
'#title': textarea2
- Navigate to the sharepoint_connector configure webform page; admin/config/sharepoint_connector/settings/webforms/configure?id=hierarchy 1&machine=hierarchy_1
- Result: only see top level fields; checkbox1, page1, Created
- Expected result: see all fields; checkbox1, textarea1, page1, textarea2, Created
Proposed resolution
/src/Form/SharepointConnectorFormWebformFields.php
Instead of using
$webform_fields = $webform->getElementsDecoded();
Use
$webform_fields = $webform->getElementsDecodedAndFlattened();
getElementsDecoded returns:
Array (
[checkbox1] => Array (
[#type] => checkbox
[#title] => checkbox1 )
[flexbox1] => Array (
[#type] => webform_flexbox
[textarea1] => Array (
[#type] => textarea
[#title] => textarea1 ) )
[page1] => Array (
[#type] => webform_wizard_page
[#title] => page1
[textarea2] => Array (
[#type] => textarea
[#title] => textarea2 ) ) )
Whereas getElementsDecodedAndFlattened returns
Array (
[checkbox1] => Array (
[#type] => checkbox
[#title] => checkbox1 )
[flexbox1] => Array (
[#type] => webform_flexbox )
[textarea1] => Array (
[#type] => textarea
[#title] => textarea1 )
[page1] => Array (
[#type] => webform_wizard_page
[#title] => page1 )
[textarea2] => Array (
[#type] => textarea
[#title] => textarea2 ) )
Alternative:
We could modify foreach to drill down into the array, but the current implementation does not account for hierarchy and I do not currently see a use case to do so.
Notes, out of scope for this issue:
- We should also exclude "webform_wizard_page" as an element type; reason: this contains no value and is just for layout purposes. Need to see if there is a way to identify layout elements.
- Should also look at how the webform title and id are being passed in.
- /admin/config/sharepoint_connector/settings/webforms/configure returns a null error since the parameters are not present
- Typically I have seen parameters passed as just part of the URL, something like /admin/config/sharepoint_connector/settings/webforms/[webform id]. This would eliminate a need to catch an exception as that path would no longer exist. The additional change would be to get the webform title from the webform entity.
Remaining tasks
User interface changes
API changes
Data model changes