Problem/Motivation
When we create a custom config entity, we should define the schema for the data, so basically describe each field - data type, label, description.
But to create the add/edit form, we have to create a form, where should describe the entity's fields again!
Sounds not good, right? Let's simplify this!
Proposed resolution
The idea is to get the config entity schema and automatically generate the add/edit form for the custom entity. With this, all that you have to do is just configure the form handles in your custom configuration form like this:
#[ConfigEntityType(
id: 'schema_form_design',
...
handlers: [
'form' => [
'add' => SchemaFormEntityForm::class,
'edit' => SchemaFormEntityForm::class,
'delete' => EntityDeleteForm::class,
],
],
and that's it!
Also, introduce a configuration entity "Schema Form Design" that will contain the additional information related to the form building process, which will be applied to the form. This approach should allow the customization of the schema forms by extending and overriding the automatically generated form elements, without using custom code.
| Comment | File | Size | Author |
|---|---|---|---|
| #7 | schema_form-3525199-customize-forms-by-config-7.patch | 54.23 KB | murz |
Issue fork schema_form-3525199
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 #2
murzComment #4
murzComment #5
murzImplemented the first implementation in the MR. Attach a static patch file with those changes, to make it possible to use in composer until #3204538: GitLab Merge Requests Unable to Generate Incremental Patch Files is resolved.
Comment #6
murzImproved the implementation. Attach a static patch file with the last changes, to make it possible to use in composer until #3204538: GitLab Merge Requests Unable to Generate Incremental Patch Files is resolved.
Comment #7
murzSimplified generating the root of the form and added skipping langcode for forms. Attaching a static patch file with those changes, to make it possible to use in composer until #3204538: GitLab Merge Requests Unable to Generate Incremental Patch Files is resolved.
Comment #8
murzExtended the idea to automatically generate forms for any config entity.
Comment #10
murzImplemented, tested, and merged!
Comment #11
murz