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.

Command icon 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

murz created an issue. See original summary.

murz’s picture

Title: Implement overriding the schema form fields using configuration » Implement customizing the schema form fields using configuration
Assigned: Unassigned » murz
Issue summary: View changes

murz’s picture

Title: Implement customizing the schema form fields using configuration » Introduce Schema Form Design to allow customizing schema forms
Issue summary: View changes
murz’s picture

Status: Active » Needs review
StatusFileSize
new39.77 KB

Implemented 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.

murz’s picture

Improved 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.

murz’s picture

StatusFileSize
new54.23 KB

Simplified 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.

murz’s picture

Title: Introduce Schema Form Design to allow customizing schema forms » Automatic form generation for Config Entities with customizing design by the configuration
Issue summary: View changes

Extended the idea to automatically generate forms for any config entity.

  • murz committed 58bffa8f on 1.0.x
    Issue #3525199 by murz: Automatic form generation for Config Entities...
murz’s picture

Status: Needs review » Fixed

Implemented, tested, and merged!

murz’s picture

Status: Fixed » Closed (fixed)