-
-
Notifications
You must be signed in to change notification settings - Fork 825
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
APIv4 - Add metadata about class args #22831
Conversation
(Standard links)
|
7ddad41
to
8df967c
Compare
OK, so I didn't realize that API Explorer had any special bits for
With just
We need this functionality because the PHP class-binding looks quite different. (Change Civi\Api4\CustomValue::get('Education'); The addition of var extraArg = _.camelCase(entityInfo.name.substr(entityInfo.virtual_entity_prefix.length));
var phpCode = entityInfo.class + '::get(' + extraArg + ')'; $extraArg = CRM_Utils_String::convertStringToCamel(substr($entityInfo['name'], strlen($entityInfo['virtual_entity_prefix'])));
call_user_func([$entityInfo['class'], 'get'], $extraArg); It might be cleaner to affirmatively specify what should pass into the PHP class (eg
var phpCode = entityInfo.class + '::get(' + entityInfo.class_arg + ')'; call_user_func([$entityInfo['class'], 'get'], $entityInfo['class_arg']); This contract allows the consumers to be simpler (less string-munging), and it makes the naming/mapping more flexible. (This is equally compatible with prefixes, suffixes, in-fixes, no-fixes, and completely-different-name-ixes. The underlying identities could be names or numbers or composite-keys.) But this feedback is not a hard blocker. There could be other reasons/future-directions where |
84db78c
to
379016b
Compare
That's a really good idea @totten - that simplifies the API Explorer code and could be useful in other ways. |
Yeah, looks pretty good. I did a small tweak to the variable-name that appears in generated snippets ( Merge on pass. |
ecff36f
to
febfaa1
Compare
Thanks @totten - I just pushed a slightly different tweak that keeps the same behavior as before this PR. E.g. entity name |
The CustomValue API is a virtual API, where multiple entities all get routed to the same class if they share the prefix "Custom_", and pass a class arg to the php factory functions e.g. `CustomValue::get('MyCustomGroup')`. Instead of hard-coding this idea into the now it's part of the entity metadata so that other APIs, notaby ECK, can use a similar pattern.
febfaa1
to
e01b30d
Compare
Overview
The
CustomValue
API is a virtual entity, where multiple api entities all get routed to the same class by virtue of all sharing the prefix "Custom_" and pass a class arg to the php factory functions e.g.CustomValue::get('MyCustomGroup')
.Instead of hard-coding this idea into the API Explorer now it's part of the entity metadata so that other APIs, notaby ECK, can use a similar pattern.
Before
Hard-coded
After
Flexible, uses metadata.