Generated with the help of an LLM. Guided and reviewed by a human
Problem/Motivation
FieldBlock::formatterSettingsProcessCallback() runs before Form API processes the formatter elements. As a result, FieldBlock::getFormatter() uses raw form input as the formatter configuration.
Browsers do not submit unchecked checkboxes, and FormatterPluginManager::prepareConfiguration() only adds top-level defaults. This can leave nested formatter settings with missing keys.
#3643250: Layout builder's AJAX error when adding a Changed field block with time difference disabled addressed this for TimestampFormatter (time_diff.enabled) by overriding getSetting(). However, contributed formatters with nested checkbox settings can encounter the same "Undefined array key" warning.
Proposed resolution
Update FieldBlock::getFormatter() to use raw form input only to determine the formatter type. Use the stored configuration for its settings, or the new formatter's default settings if the type has changed. Form API will continue to process the submitted settings.
With this change, the TimestampFormatter::getSetting() override introduced in #3643250: Layout builder's AJAX error when adding a Changed field block with time difference disabled can be removed.
An alternative is to update PluginSettingsBase::mergeDefaults() to merge nested defaults. However, this would affect getSettings() for all formatters and widgets. Without configuration schema, it also cannot reliably distinguish mappings from sequences.
Remaining tasks
- Coordinate with #3643483: Layout Builder loses checkbox defaults when changing field formatters, which also changes
FieldBlock::getFormatter(). - Preserve the regression test from #3643250: Layout builder's AJAX error when adding a Changed field block with time difference disabled.
Issue fork drupal-3644351
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments