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

APIv4 - Setting api misc fixes & tests #20191

Merged
merged 2 commits into from
May 5, 2021

Conversation

colemanw
Copy link
Member

Overview

Fixes the setting api to correctly handle pseudoconstants & field suffixes

Before

Setting pseudoconstants not handled well.

After

Works better & covered by tests.

@civibot
Copy link

civibot bot commented Apr 29, 2021

(Standard links)

@civibot civibot bot added the master label Apr 29, 2021
@colemanw colemanw force-pushed the apiSettingsFixes branch 2 times, most recently from 339ebc1 to 3dbebc6 Compare April 29, 2021 21:49
@@ -437,7 +437,7 @@ public static function geoProvider() {
*
* @throws \CRM_Core_Exception
*/
public function taxDisplayOptions() {
public static function taxDisplayOptions() {
Copy link
Member Author

Choose a reason for hiding this comment

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

@eileenmcnaughton the new unit test which checks settings pseudoconstants hit this (PHP error non-static method called statically).

public function testGetFieldsGroupFilters($version) {
$this->_apiversion = $version;
public function testGetFieldsGroupFilters() {
$this->_apiversion = 3;
Copy link
Member Author

Choose a reason for hiding this comment

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

group is a deprecated property so APIv4 doesn't need to test it.

Copy link
Contributor

Choose a reason for hiding this comment

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

Does apiv4 still permit filtering on it if set. We kinda deprecated it as a required key but kept the idea you could filter by it (e.g if you wanted to present all the settings defined by one extension on a page). I can't recall if it was reliable or not

Copy link
Member Author

Choose a reason for hiding this comment

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

No. I was following the docs which state it is a deprecated property. I didn't want APIv4 returning stuff that's already deprecated. That means it wouldn't be able to filter on it either.

@colemanw colemanw mentioned this pull request May 3, 2021
@@ -69,9 +69,7 @@ public static function getMetadata($filters = [], $domainID = NULL, $loadOptions
}

self::_filterSettingsSpecification($filters, $settingsMetadata);
if ($loadOptions) {
Copy link
Contributor

Choose a reason for hiding this comment

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

@colemanw so this seems to result in us iterating through every setting and doing noting if loadOptions is false - as opposed to just skipping. Why the change?

Copy link
Contributor

Choose a reason for hiding this comment

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

Also - I note loadOptions is not cached so that doesn't mitigate the empty iteration

Copy link
Member Author

Choose a reason for hiding this comment

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

You're right. I originally had this doing more but had to change it back due to a failing test.

Copy link
Contributor

Choose a reason for hiding this comment

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

@colemanw is it going to do more again soon? If so I guess it's Ok to merge as is

Copy link
Member Author

Choose a reason for hiding this comment

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

Probably not. I've replaced the conditional as before.

*/
protected static function loadOptions(&$settingSpec) {
protected static function fillOptions(&$settingSpec, $getOptions) {
Copy link
Contributor

Choose a reason for hiding this comment

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

So the thing I find kinda messy is that getOptions is really a 3 way option it

  • NO
  • YES
  • do it as an array

I feel like is_array() to determine that last one is a bit opaque

Copy link
Member Author

Choose a reason for hiding this comment

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

Well, yea but that's way outside the scope of this PR IMO.

Copy link
Member Author

Choose a reason for hiding this comment

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

It's really an APIv4 documentation issue.

Copy link
Contributor

Choose a reason for hiding this comment

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

@colemanw well maybe at the api level - but at the level of this function we could pass something pretty clear

Copy link
Member Author

Choose a reason for hiding this comment

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

Unfortunately, I don't think we can. To maintain backward-compat it needs to be able to return a flat array if true and in order to correctly serve data to APIv4 it needs to be able to fetch name, label, etc if array.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure I'll rename that param too.

Copy link
Member Author

Choose a reason for hiding this comment

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

I renamed it but resisted the temptation to turn it into a boolean because eventually we'll add support for more return values.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm I feel like Civi is full of that sort of good intention code which makes less & less sense after the extra thing isn't done months later. I'd probably go with what actually makes sense with the code now as it's a protected function - but failing that beef up the comments explaining the rationale for the param in the docblock

Copy link
Member Author

Choose a reason for hiding this comment

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

@eileenmcnaughton I renamed the variable & added a comment. I don't think this is one of those cases because it's not broken or half-functional. It works, this just leaves the door open for further enhancements.

Copy link
Contributor

Choose a reason for hiding this comment

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

OK - it still feels a bit too much like magic to me but at least the docs cover it now

@colemanw colemanw force-pushed the apiSettingsFixes branch from a464865 to 4778438 Compare May 4, 2021 21:27
colemanw added 2 commits May 4, 2021 17:52
Fixes the setting api to correctly handle pseudoconstants & field suffixes
@colemanw colemanw force-pushed the apiSettingsFixes branch from 4778438 to 6fb8554 Compare May 4, 2021 21:53
@eileenmcnaughton eileenmcnaughton merged commit eeeb9b4 into civicrm:master May 5, 2021
@eileenmcnaughton eileenmcnaughton deleted the apiSettingsFixes branch May 5, 2021 00:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants