Form Builder

Form Builder provides a flexible form interface allowing editing a variety of CiviCRM entities as well as a developer interface.

If an expected element for an Entity is missing from Form Builder, it's likely that the <html><type> needs to be added to the xml file for that Entity so that Form Builder can render it.

The GUI can be extended via the civi.afform_admin.metadata event.

This event is used for adding entities, elements, input types, etc.

It is also possible to expose entities by adding a declaration. To do this:

  1. Add the mixin <mixin>afform-entity-php@1.0.0</mixin> to your extension's info.xml file (note: for backward compatability with versions < 5.50 you must add a shim.
  2. Ensure the entity in question has apiv4 CRUD entities (these get generated automatically if using civix with an extension)
  3. Create a php file in the following location - afformEntities/EntityName.php as you can see here in the deduper extension. For more complex examples see core.
  4. Add the following detail - where url-autofill is the default value for autofill when adding this entity to a form.

return [
  'entity' => 'ContactNamePair',
  'label' => 'Equivalent name pair',
  'defaults' => "{'url-autofill': '1'}",
5. An entity can be available for "Submission forms" and/or for "Field blocks". In order for the entity to be available for Submission forms, add 'type' => 'primary' example or only as Field blocks, leave blank or add 'type' => 'join' example. A Field block (or join) is only available in relation to a primary entity.

Core afform entities have examples of other parameters that can be added such as repeat_max, unique_fields, boilerplate, icon, alterFields, and data defaults. Be sure to test them out to see what works best with a custom entity.