-
☆ A M B ☆
- 24,524 Posts
What would be the best way to get a setting value, first checking for user settings, then group settings, then context settings, then default system settings?
Depends on the way you want your script to handle those settings and if you want the user's setting to override the system settings and vice versa.
Are you trying to display them or use them to compare against for conditionals?
-
☆ A M B ☆
- 24,524 Posts
Specifically, I've had to hack Ace to get it to recognize context settings, but it's a very specific hack and I'd prefer to adjust it so that Ace will respect the settings in their order - first user, then group, then context, then default system setting.
At lines 85 and 105 I'm replacing $modx->getOption('use_editor') with $modx->controller->context->getOption('use_editor')
if ($modx->controller->context->getOption('use_editor'))
...
if ($modx->event->name == 'OnDocFormPrerender' && !$modx->controller->context->getOption('use_editor'))
Well you could nest several if statements or use a switch or iterate through a collection of settings in a foreach.
If I'm understanding correctly you want to check if the setting exists at each level till you get from user to system progressively, then set the topmost setting, i.e., user if setting exists }else{ group, and so on?
-
☆ A M B ☆
- 24,524 Posts
Yes. I had always thought that getOption() would automatically follow that progression, until I ran across this actual use case and found out that it doesn't.
You know, you could simply write it into the method for getOption that would do the hierarchal setting check the way you need it to.
I think that would benefit the core. It could actually be done so getOption($setting,,,,,true) would trigger the hierarchal check. Default it to false.
Just a thought.
Quote from: sottwell at Dec 27, 2014, 12:18 PMYes. I had always thought that getOption() would automatically follow that progression, until I ran across this actual use case and found out that it doesn't.
AFAIK, it does, with the possible exception of group settings. The precedence order is:
User Setting
Context Setting
System Setting
If you include $scriptProperties as the second argument, the order is:
Property in tag
Property in Property Set
Default Property
User Setting
Context Setting
System Setting
This has always worked whenever I've tested it, though the addition of group settings might have changed things.
-
☆ A M B ☆
- 24,524 Posts
I was interested in the context that the resource being edited was in, not the actual context (mgr) that Ace was being used in. That adds a level of complexity to determining what settings to use.
Doesn't the context_key of the resource tell you that?
-
☆ A M B ☆
- 24,524 Posts
Yes, but Ace doesn't know about that. I was told that I needed to use this (I forget who told me, but it does work)
$modx->controller->context->getOption('use_editor')