Skip to content
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

Entity subtype is a required API field #138

Closed
MegaphoneJon opened this issue Jul 25, 2024 · 4 comments · Fixed by #144
Closed

Entity subtype is a required API field #138

MegaphoneJon opened this issue Jul 25, 2024 · 4 comments · Fixed by #144

Comments

@MegaphoneJon
Copy link

When you create a new entity, you're given the option (but it's not required) to create a subtype.

However, if you don't create a subtype:

  • The default SearchKit won't have an "Add" button for your entity.
  • If you try to create a record via API, it will fail because you didn't pass a subtype, which is required.
@jensschuppe
Copy link
Collaborator

Subtypes are actually a requirement for entities of an ECK entity type being created, see #5. The analogy is that you can't have e.g. activities without an activity type.

So the Afform for listing entities probably shouldn't be available until subtypes are created, or at least a notice being shown that a subtype is required.

I can't see how the add/edit form for an ECK entity type should behave differently with subtypes being required, as you'll have to be able save the entity type before creating subtypes for it. But I'm happy to receive suggestions for that. Maybe a notice on the form would suffice?

@aydun
Copy link

aydun commented Nov 14, 2024

Just hit the same thing - create an entity & create a FormBuilder submission form to create new instances. On hitting 'Submit' it says 'Saved' but silently fails, except for a message in the log saying:
2024-11-14 11:37:26+0000 [debug] Silently ignoring exception in Afform processGenericEntity call for "Eck_Transport_Request1". Message: Mandatory values missing from Api4 Eck_Transport_Request::save: subtype
Failing to save the submitted data warrants more than just a debug line in the log!

For my entity, there is no obvious subtype. I might eventually want a subtype but requiring one is not intuitive. If you need one from an ease of coding perspective (as suggested in #5), then maybe create a 'default' type automatically that can be renamed or removed by those that need subtypes.

@jensschuppe
Copy link
Collaborator

The core afform code has this comment:

// What to do here? Sometimes we should silently ignore errors, e.g. an optional entity
// intentionally left blank. Other times it's a real error the user should know about.

I'd say that core afform should not ignore the exception when mandatory values are missing for the entity. The exception comes with the mandatory_missing error code, so this should be easily detectable.

I wouldn't want to re-implement the civi.afform.submit event for this in ECK. I agree though, that in ECK it should be more obvious that a subtype is required (and should be), although you can't get this behavior in the UI, as there is no default submission form for ECK entities without a subtype. Maybe ECK's implementation of the civi.afform_admin.metadata event should not expose ECK entities without subtypes to afform at all, see #144.

@jensschuppe
Copy link
Collaborator

I created civicrm/civicrm-core#31479 for FormBuilder forms to not silently fail with missing mandatory values.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants