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
    Is there any way to determine the context in which a new resource is being created? This would be used in a plugin that should only be active when a resource is being created in a given context.

    Of course, if the "Empty Cache" checkbox setting was an option like all of the others, a plugin to uncheck it wouldn't be necessary.
      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
      $resource->get('context_key');
        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
        That's only available if it's an already existing resource. A new resource doesn't appear to have such an object. CacheManager even checks for that, and just returns if it's a new resource.
          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
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          Hm. In the create.class.php I see a public variable, "$workingContext". I wonder how I can get my hands on that...

          Or maybe OnBeforeDocFormSave would be a better place to fix that, the resource object is available at that point, so I should be able to empty that field. I was just hoping to find some way to get at the working context OnBeforeDocFormRender to uncheck the checkbox, like CacheManager does for updating resources.
            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
            • 28042 ☆ A M B ☆
            • 24,524 Posts
            I finally managed to track down the code that sets that. /manager/controllers/default/resource/create.class.php on line 105. All of the other options are controlled by a setting except that one. So all I need to do is add a System Setting and clone the other lines:
            'richtext' =>  $this->context->getOption('richtext_default', true, $this->modx->_userConfig),
            'hidemenu' => $this->context->getOption('hidemenu_default', 0, $this->modx->_userConfig),
            'published' => $this->context->getOption('publish_default', 0, $this->modx->_userConfig),
            'searchable' => $this->context->getOption('search_default', 1, $this->modx->_userConfig),
            'cacheable' => $this->context->getOption('cache_default', 1, $this->modx->_userConfig),
            'syncsite' => $this->context->getOption('syncsite_default', 1, $this->modx->_userConfig),
            

            Works like a champ. Set it to "Yes" in System Settings, and to "No" in a Context's settings, and creating new resources in the context will have it unchecked.
              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
              I don't suppose the default_context System Setting would help.
                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
                No, that just sets the default "starting" context, which is usually "web". For example, in multi-language setups, you might want to change that to some other language at some point.
                  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
                  • 28042 ☆ A M B ☆
                  • 24,524 Posts
                  As soon as I get github sorted out, I'll be making a pull request for that change, so that a new System Setting or Context Setting can be used to determine whether or not that checkbox should be checked by default. That gets to the root of the problem.

                  I thought of elements as well, but they all have that checkbox right on the main editing tab, so it's not such a pain in the neck to clear it. Besides, they don't get created or updated as often as resources do.
                    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