civi.afform_admin.metadata¶
Summary¶
This Symfony event is dispatched to alter metadata for the FormBuilder GUI. It allows developers to add or customize entities, elements, styles, permissions, input types, and submission tokens in the editor interface.
Definition¶
This event is dispatched via the Symfony EventDispatcher.
public static function onAfformAdminMetadata(\Civi\Core\Event\GenericHookEvent $event): void
Parameters¶
\Civi\Core\Event\GenericHookEvent $event
Event Properties¶
Since this event uses GenericHookEvent, properties are accessed dynamically:
$event->entities:array- List of entities that can be used in the FormBuilder GUI. Each item has array keys:name(string)label(string)icon(string: "fa-*")type(string: "primary"|"secondary")defaults(string: js object).$event->elements:array- Static elements that can be added to a form, keyed by name. Each item has array keys:title(string) Title shown in Editorafform_type(array) Form types this element is used forelement(array) Default markup for this elementdirective(string) Specify directive name in dash format (should match['element']['#tag'])admin_tpl(string) Editor template. Extensions can provide their own template for editing this element type, by adding an Angular module with base page'civicrm/admin/afform'.$event->inputTypes:array- Form widgets used to represent a field.$event->styles:array- Bootstrap style strings available in the GUI.$event->permissions:array- Permissions that can be set for an Afform.$event->dateRanges:array- Date range options.$event->submissionTokens:array- List of tokens which can be used in the confirmation screen or redirect URL after the user submitted the form. To return the token values, the Save action of your entity should return this as fields. Each item has array keys:token(string) Name of the token.label(string) The label of the token.description(string) Optional description of the token.
[!NOTE] Regarding the
submissionTokens. Check the form processor extension for an implementation. See the implementation of the event listenercivi.afform_admin.metadataand the implementation of the API4 Save action which returns the token values.
Example¶
use Civi\Core\Event\GenericHookEvent;
public static function onAfformAdminMetadata(GenericHookEvent $event): void {
// Add a custom style option to the GUI editor
$event->styles[] = 'my-custom-form-class';
}