Add DAO fields to API metadata when the entity type name is known #127
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Follow-up to #125
Since the DAO methods for compiling schema fields are static, but ECK entities rely on the entity type for their metadata (table name, etc.), the
CRM_Eck_DAO_Entity::fields()
method needs to be called after initialization, and can't be relied upon for further calls for different entity types. #125 makes the method not return anything for uninitialized calls.This PR uses the Spec Provider to gather DAO fields, as they would otherwise not be part of the entity metadata at all (causing e.g. search displays or even the entire SearchKit admin UI to crash).
@colemanw I had to copy a private method
\Civi\Api4\Service\Spec\SpecGatherer::setDynamicFk()
to save us from changes to Core. I tried to make this more generic, see civicrm/civicrm-core@master...jensschuppe:civicrm-core:daoSpec - this would have allowed for overriddengetSupportedFields()
methods in DAO classes that depend on the API entity name, but I'm not sure this would cover all relevant cases. And since DAOs are on their way out of Core anyway, I didn't file a PR to Core. Anyway, I'd still appreciate you reviewing.