Problem/Motivation
Creating a SwiperFormatter config entity programmatically without providing all properties (e.g. swiper_options) causes a fatal error (HTTP 502) when loading the edit form. This is because the entity class does not define default values for its properties, and the form class expects them to be populated.
Currently, SwiperFormatterForm::prepareEntity() handles this for the add form by copying options from the default entity, but this only covers the form context and not programmatic creation (e.g. from code, Drush, or migrations, tests).
There is no preCreate() implementation on the entity class to ensure sensible defaults are set whenever create() is called, regardless of context.
Steps to reproduce
$entity = \Drupal::entityTypeManager()
->getStorage('swiper_formatter')
->create([
'id' => 'test_swiper',
'label' => 'Test Swiper',
'description' => 'Test Swiper Description',
]);
$entity->save();
// Visit /admin/config/content/swiper-formatter/test_swiper → 502 fatal error.
Proposed resolution
Add a preCreate() method to SwiperFormatter that loads the default entity and uses its swiper_options and status as defaults for newly created entities:
This covers both programmatic creation and the add form, replacing the form-level logic currently in prepareEntity().
Remaining tasks
- Implement
preCreate()on SwiperFormatter - Remove
prepareEntity()from SwiperFormatterForm (no longer needed)
This was discovered while writing tests for #3573757, where programmatic entity creation without full properties caused a fatal error. Resolving this is a prerequisite for completing the test coverage in that issue.
Issue fork swiper_formatter-3574694
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
Comment #3
bbu23Comment #6
bbu23Comment #8
bbu23Will be available in 2.1.0