- Issue created by @johnny5th
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.
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.
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.
Active
1.0
Code