ViewModeMapping form not properly processing inputs

Created on 29 May 2024, 27 days ago

Problem/Motivation

The submit handler of ViewModeMappingSettings doesn't properly handle form inputs.

There's a comment in the handler describing the use of $form_state->getUserInput() rather than $form_state->getValue('sdc_display') due to the mapping values disappearing when field formatter settings are adjusted.

I had a problem with both a string property using an enum for possible values and a boolean property defaulting to true. I've only tried debugging the boolean problem. getUserInput gets the raw value of the checkbox, so the value for unchecked is NULL and checked is "1", while getValue('sdc_display') returns false and true respectively. In effect, you're not able to set a boolean property to False if it has a default value of True.

Steps to reproduce

Create a component with a boolean property defaulting to True. Manage the display of an entity and render using this component (I'm using a paragraph bundle in this instance). Set a static value of False on the boolean property.

Proposed resolution

Figure out a way to maintain the values of the selected component even after a different AJAX method breaks the form cache. In testing, hardcoding $selected_component in line 69 of ViewModeMappingsSettings.php to my desired component properly keeps the mapping values in the form cache, but I don't know enough about form internals to move forward, or if there's a negative consequence for re-injecting the mapping values during a separate module's AJAX call.

πŸ› Bug report
Status

Active

Version

1.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States johnny5th

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

Comments & Activities

Production build 0.69.0 2024