In PatternDisplayFormTrait:processFormStateValues() the submitted values from a UI Patterns configuration form are normalized before being saved.
There are a couple of places where edge cases lead to cruft being saved.
First, the $settings['variants'] key is unset only conditionally, that is, in the case that there's a selected variant:
if (isset($settings['variants']) && isset($settings['variants'][$settings['pattern']])) {
$settings['pattern_variant'] = $settings['variants'][$settings['pattern']];
unset($settings['variants']);
}
The result is that, when the current pattern doesn't have a selected variant (possibly because it doesn't support variants), the (always superfluous) 'variants' data are saved for all available patterns.
Proposed fix:
if (isset($settings['variants'])) {
if (isset($settings['variants'][$settings['pattern']]) {
$settings['pattern_variant'] = $settings['variants'][$settings['pattern']];
}
unset($settings['variants']);
}
Second, there are edge cases where the code normalizing the $settings['pattern_mapping'] can also leave cruft.
The current code is:
// Normalize only when necessary.
if (isset($settings['pattern_mapping'][$settings['pattern']]['settings'])) {
...
}
If there is no selected pattern - for example, in a context where the pattern is not required - the non-normalized data for all patterns are saved.
Proposed fix:
// Normalize only when necessary.
if (isset($settings['pattern_mapping'][$settings['pattern']]['settings'])) {
...
}
else {
unset($settings['pattern_mapping']);
}
In
PatternDisplayFormTrait:processFormStateValues()
the submitted values from a UI Patterns configuration form are normalized before being saved.There are a couple of places where edge cases lead to cruft being saved.
First, the
$settings['variants']
key is unset only conditionally, that is, in the case that there's a selected variant:The result is that, when the current pattern doesn't have a selected variant (possibly because it doesn't support variants), the (always superfluous) 'variants' data are saved for all available patterns.
Proposed fix:
Second, there are edge cases where the code normalizing the
$settings['pattern_mapping']
can also leave cruft.The current code is:
If there is no selected pattern - for example, in a context where the pattern is not required - the non-normalized data for all patterns are saved.
Proposed fix: