hide_if_no_transitions hides the composite subfields from other modules

Created on 20 September 2022, almost 2 years ago
Updated 5 June 2023, about 1 year ago

Problem/Motivation

When hide_if_no_transitions setting is enabled, it causes the workflow elements subfields to not be available to anything that needs to know about it (e.g. webform_views to render the subfields individually). However, other kinds of composite fields have no issues.

The reason is because Element\WebformWorkflowsElement::getCompositeElements()'s return value is used for a lot of things. It's used to know a composite's subfields, know a composite field's default properties, know a composite's field's default values, and even do the rendering of the element. In this case, when getCompositeElements() is called to learn of a composite's subfields and hits the following condition, the caller will get an empty array. This causes $element['#webform_composite_elements'] to become empty and make other integrations think the workflows field has no subfields.

// If setting enabled, hide completely
if (count($availableTransitions) == 0 && isset($element['#hide_if_no_transitions']) && $element['#hide_if_no_transitions']) {
  return [];
}

Steps to reproduce

1. Install webform_workflows_element and webform_views.
2. Create a webform with a custom composite of textfields, and a workflows element.
3. Create a view of the webform, adding both fields as their subfields.
4. Enable hide_if_no_transitions on the workflow field.
5. Repeat Step 3

On Step 5, you will not see the workflow composite's subfields but you will see the custom composite's subfields.

Proposed resolution

- Return only the hidden fields when $element['#value'] is not set. As far as I can tell, $element['#value'] is the only hint to know if getCompositeElements() is being called to render the element. If it's not set, the method is being called for something else that doesn't involve a render.
- hide_if_no_transitions should not cause admin options to go missing. It should only hide the field during render.

Remaining tasks

- Patch
- Review
- Merge

User interface changes

None

API changes

None

Data model changes

None

πŸ› Bug report
Status

Fixed

Version

1.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States fskreuz

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.69.0 2024