We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 17232
    • 0 Posts
    Hello everyone.
    I try to overwrite settings for a user group.
    I use modx 2.1.1-pl.

    How can this be done?

    For example: A user is created with the Login->Register snipped
    and added to the Group "Writer". Now I want to overwrite
    the setting xxx for every user automatically to a new value.

    Thank you, Louis
      • 17232
      • 0 Posts
      So, I am currently playing arround with contexts.
      It seems like this is the only solution which
      allows me to do what I want.

      I currently created another context, put every page into it
      and then set a setting xxx for it.

      After setting the wayfinder contexts option (comma seperated) the menu
      at least shows up the root containers again.

      If I click on a link of a page which is in the writer context, the page
      ID is referenced in the url, but I only see the landing page (id 0).
      If I click on a link of a resource which is in the web context,
      everything works well.

      Does someone know what is causing this behaviour?

      It would also be interresting to know if I am abusing the contexts
      system in any way.

      Thank you, Louis
        • 3749
        • 24,544 Posts
        I would strongly advise using Resource Groups or User Settings rather than contexts.
          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
          • 17232
          • 0 Posts
          Ok. I created this snippet to add usersettings via a register &posthook.

          Feel free to use it, but it may need some more error checking.

          <?php
          $username = $hook->getValue('username');
          if(empty($username)) {
           $hook->addError('user','Username field empty');
           return false;
          }
          $usrobject = $modx->getObject('modUser',
                array('username' => $username));
          $userid = $usrobject->get('id');
          if(empty($userid)) {
           $hook->addError('user','Error getting user object');
           return false;
          }
          //Create the user image dir
          $assetspath = $modx->getOption('assets_path');
          mkdir($assetspath.'images/'.$username);
          //Add the user setting
          $setobject = $modx->newObject('modUserSetting');
          $setary = array(
           'user' => $userid,
           'key' => 'filemanager_path',
           'value' => '/assets/images/'.$username,
           'area' => 'File System'
          );
          $setobject->fromArray($setary,'',true);
          $setobject->save();
          
          //Clear the cache
          $modx->cacheManager->refresh(array('system_settings' => array()));
          return true;


          [EDIT]
          Here is a really nice tutorial about login/register hooks
          http://rtfm.modx.com/display/ADDON/Login.Using+Pre+and+Post+Hooks
            • 3749
            • 24,544 Posts
            Thanks for the contribution. I’m sure many people will find it useful. cool
              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