We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 28042 ☆ 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?
      Studying MODX in the desert - http://sottwell.com
      Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
      Join the Slack Community - http://modx.org
      • 49407
      • 159 Posts
      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?
        • 28042 ☆ 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'))
          Studying MODX in the desert - http://sottwell.com
          Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
          Join the Slack Community - http://modx.org
          • 49407
          • 159 Posts
          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?
            • 28042 ☆ 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.
              Studying MODX in the desert - http://sottwell.com
              Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
              Join the Slack Community - http://modx.org
              • 49407
              • 159 Posts
              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.
                • 3749
                • 24,544 Posts
                Quote from: sottwell at Dec 27, 2014, 12:18 PM
                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.

                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.


                  Did I help you? Buy me a beer
                  Get my Book: MODX:The Official Guide
                  MODX info for everyone: http://bobsguides.com/modx.html
                  My MODX Extras
                  Bob's Guides is now hosted at A2 MODX Hosting
                  • 28042 ☆ 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.
                    Studying MODX in the desert - http://sottwell.com
                    Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                    Join the Slack Community - http://modx.org
                    • 3749
                    • 24,544 Posts
                    Doesn't the context_key of the resource tell you that?
                      Did I help you? Buy me a beer
                      Get my Book: MODX:The Official Guide
                      MODX info for everyone: http://bobsguides.com/modx.html
                      My MODX Extras
                      Bob's Guides is now hosted at A2 MODX Hosting
                      • 28042 ☆ 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')
                        Studying MODX in the desert - http://sottwell.com
                        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                        Join the Slack Community - http://modx.org