Webform field hierarchy

Created on 3 January 2025, 19 days ago

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

  1. Create a new webform; /admin/structure/webform/add
  2. Name it whatever you want; "hierarchy 1"
  3. 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
  4. Navigate to the sharepoint_connector configure webform page; admin/config/sharepoint_connector/settings/webforms/configure?id=hierarchy 1&machine=hierarchy_1
  5. Result: only see top level fields; checkbox1, page1, Created
  6. 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:

  1. 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.
  2. Should also look at how the webform title and id are being passed in.
    1. /admin/config/sharepoint_connector/settings/webforms/configure returns a null error since the parameters are not present
    2. 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

πŸ› Bug report
Status

Active

Version

1.0

Component

Code

Created by

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024