-
-
Notifications
You must be signed in to change notification settings - Fork 817
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dispatch an event for registering Afform entities #21899
Conversation
(Standard links)
|
I don't quite get why entity-specific logic is to be implemented within Afform's post-processing in the first place. Isn't the API supposed to do all the heavy lifting for each entity? I see Afform validating contact entities having either a name or an e-mail address in civicrm-core/ext/afform/core/Civi/Api4/Action/Afform/Submit.php Lines 110 to 140 in 386ef14
If at all, entity-specific logic would be necessary in constructing the form, e.g. fields being dependent on something, at least if Afform forms are considered a configurable UI for the API that exposes logic to the user (can't think of an example for this right now). Anyway, Afform allowing all entities to be used to create forms for (i.e. |
The Contact API cannot perform that check because it doesn't know whether or not you are planning to add an email address after creating a contact. That's a specific example of a more general issue where Afform entity handling is different from general API processing because of the context of a form with user input. API CRUD operations lack this context and so are more permissive of input which either should not be permitted on a form, or should be subject to additional business logic. |
It sounds like this has stalled? If there are no short-term plans to work on it then I'd suggest closing and moving to gitlab. |
Given that the following was suggested by @colemanw:
and the fact that we've moved away from using Afform forms for our "virtual entity" extension for now, moving this to GitLab for documenting the issue seems reasonable to me. I'll let @colemanw decide however. |
This is now replaced by #23303 |
Overview
Currently, Afform forms can only be created for hard-coded entities or entities provided by extensions through a PHP file for each entity. This adds an event which extensions can subscribe to for registering entities, e.g. "virtual" entities which no PHP files can be created for.
Before
No support for virtual entities.
After
Virtual entities supported by dispatching an event when generating the list of events.
Technical Details
Since CiviCRM Core supports virtual entities for API4 with #21771, the Afform builder should support those as well. Maybe this can be more generic in the future, i.e. allowing to build forms for all API4 entities.
Comments
With this, a refactoring of
civicrm-core/ext/afform/admin/Civi/AfformAdmin/AfformAdminMeta.php
Lines 162 to 168 in 82106bd