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

Don't expose ECK entities without subtypes to afform #144

Merged
merged 2 commits into from
Nov 14, 2024

Conversation

jensschuppe
Copy link
Collaborator

Fixes #138.

ECK entity types without a subtype should not be made available to FormBuilder as submitting entity forms for entities without a subtype will silently fail.

@jensschuppe jensschuppe added enhancement New feature or request status:needs review Code needs review and testing labels Nov 14, 2024
@jensschuppe jensschuppe added this to the 1.1 milestone Nov 14, 2024
'type' => 'primary',
'defaults' => '{}',
];
if ([] !== \CRM_Eck_BAO_EckEntityType::getSubTypes($entityType['name'])) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be simplified & commented like

Suggested change
if ([] !== \CRM_Eck_BAO_EckEntityType::getSubTypes($entityType['name'])) {
// Don't expose ECK entities without subtypes; they cannot be saved without a value for the required `subtype` field
if (\CRM_Eck_BAO_EckEntityType::getSubTypes($entityType['name'])) {

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recently switched to type-safe comparisons whenever possible, as that makes code more obvious for reading and also safer for static code analysis (our current PHPStan config would complain with a boolean comparison for an array method result).
As for the comment, I think I have to agree that subtypes being required doesn't seem obvious enough, so yeah, let's add that.

@colemanw
Copy link
Collaborator

OK looks good to merge IMO

@jensschuppe jensschuppe merged commit 3d3a195 into master Nov 14, 2024
1 of 10 checks passed
@jensschuppe jensschuppe deleted the afformNoSubtypes branch November 14, 2024 13:15
@jensschuppe jensschuppe added status:fixed The issue has been resolved (usually by committing/merging code) and removed status:needs review Code needs review and testing labels Nov 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request status:fixed The issue has been resolved (usually by committing/merging code)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Entity subtype is a required API field
2 participants