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

[REF] Centralize logic for resolving settings pseudoconstants #14264

Merged
merged 1 commit into from
May 19, 2019

Conversation

colemanw
Copy link
Member

@colemanw colemanw commented May 17, 2019

Overview

Moves the pseudoconstant lookup for settings out of api3 and into the SettingsMetadata class.

Before

Code in an api3 silo.

After

Same code, better spot.

Notes

Also switches the settings form trait to use SettingsMetadata class instead of api3, and improves the filters ongetSettingsMetaData.

@civibot civibot bot added the master label May 17, 2019
@civibot
Copy link

civibot bot commented May 17, 2019

(Standard links)

@eileenmcnaughton
Copy link
Contributor

@colemanw jenkins is not sold

if (!empty($filters['name'])) {
$settingSpec = array_intersect_key($settingSpec, array_flip((array) $filters['name']));
// FIXME: This is a workaround for settingsBag::setDb() called by unit tests with settings names that don't exist
$settingSpec += array_fill_keys((array) $filters['name'], []);
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 had to add this line to mimic the old behavior.
Settings code is kind of a mess here. Settings::set() calls a validate function that doesn't actually work, and unit tests are counting on that so they can test make-believe settings :/

Copy link
Member Author

Choose a reason for hiding this comment

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

FYI this is why the validate function doesn't work: If you pass in ['name' => 'foo'] as the $filters to this function then it will spit back out an array with the key foo even if there is no such setting!. IMO that's wrong, but out of scope for this PR so I left the errant behavior as-is.

*
* @param array $settingSpec
*/
protected static function _loadOptions(&$settingSpec) {
Copy link
Contributor

Choose a reason for hiding this comment

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

so on a style thing - my understanding is we've been moving away from the leading underscore on protected functions (and in fact it's inconsistent within the class)

Copy link
Member Author

Choose a reason for hiding this comment

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

Agreed. I've updated the style thing.

@eileenmcnaughton
Copy link
Contributor

Looks OK in quick testing - I'll kick the tyres a little more by doing a little further setting form cleanup

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

Successfully merging this pull request may close these issues.

2 participants