Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
The problem is in ParagraphsStylePlugin::getStyles():
public function getStyles(ParagraphInterface $paragraph) {
$paragraph_styles = [];
foreach ($this->configuration['groups'] as $group_id => $group_configuration) {
$paragraph_styles[$group_id] = $group_configuration['default'];
}
if ($styles_config = $paragraph->getBehaviorSetting('style', 'styles')) {
// Loop over all groups to get the behavior setting.
foreach ($styles_config as $group_id => $style) {
$paragraph_styles[$group_id] = $style;
}
}
If some style didn't had default value before and paragraphs are created with empty style value for this style then when you define style default value you would expect that all paragraphs, new and old which does not have value, would get this default value.
However, the second loop will always override default styles even in the case when paragraph style value is empty.
Comment | File | Size | Author |
---|---|---|---|
#5 | default-style-value-overriden-3117486-5.patch | 3.34 KB | Berdir |
| |||
#5 | default-style-value-overriden-3117486-5-fail.patch | 1.71 KB | Berdir |
#4 | default-style-value-overriden-3117486-4.patch | 1.75 KB | Berdir |
| |||
#2 | default-style-value-overriden-3117486-2.patch | 895 bytes | pivica |
|
Comments
Comment #2
pivica CreditAttribution: pivica at MD Systems GmbH commentedHere is a patch.
Comment #3
Berdirok, so we didn't test for the case when there's an empty value in there. Instead of the separate condition, couldn't we just write this as:
$paragraph_styles = array_filter($styles_config) + $paragraph_styles;
Will also have a look at testing this
Comment #4
BerdirHm, we have no kernel tests for this stuff, and I don't want to mess with the old web tests as it would conflict with the conversion of them.
Refactored the whole thing a bit for better variable names and the suggested simplification, array_filter() and just combining it with the defaults.
Comment #5
BerdirTesting this indirectly by removing the duplicate default handling in other places, which showed that we also didn't handling defaults correctly when styles had been disabled globally.
Comment #8
BerdirCommitted. Figured out what's the problem with those random fails and will commit that separtaely.