We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 12262
    • 40 Posts
    Hello,

    I'm using Bob Ray's DefaultResourceGroup Plugin to assign the "admin" resource group automatically when saving a new resource. The "admin" resource group is my "superuser" resource group limiting access to the resources only to the super users.
    So far it works just as desired.

    Now the problem:

    If a sub editor creates a new resource it will be assigned to the "admin" resource group automatically - and so will not be editable to the sub editor anymore.

    The best way would be not to add a DefaultResourceGroup but the resource groups of the parent resource (if there's one). Any idea how this could be done?

    I know there's a feature request for this but it looks like it's not implemented yet.

    Thanks for your help in advance

    Thomas

    This question has been answered by multiple community members. See the first response.

    • discuss.answer
      • 12262
      • 40 Posts
      Hello,

      I found a working solution and would like you to have a look at it and what might be improved.
      The plugin ist for the onDocFormSave event.

      <?php
      /* only operate on new resources */
      if ($mode != modSystemEvent::MODE_NEW) return;
      
      
      $parentId = $resource->get('parent');
      
      $res = $parentId;
      /* top level documents are not regarded! */
      if ($parentId > "0")
      {
        $parentResource = $resource->getOne('Parent');
        $groups = $parentResource->getMany('ResourceGroupResources');
        foreach($groups as $name => $grpObject) 
        {
           $resGrpId = $grpObject->get('document_group');
           $success = $resource->joinGroup($resGrpId);
        }
      }



      Thomas
      • discuss.answer
        • 3749
        • 24,544 Posts
        It looks good. Since you are not using the $name variable (which is kind of misnamed anyway because it would just be the numeric index in the array) you should be able to leave it out and use this:


        foreach($groups as $group) {
             $resGrpId = $group->get('document_group');
             $success = $resource->joinGroup($resGrpId);
        }
        
          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
          • 24374
          • 322 Posts
          I dont' understand why both this plugin above and the DefaultResourceGroup plugin are set to work when you SAVE the resource. It would be more intuitive to have the groups checked off when a new resource is created, so that the user will see these settings present when they go to save the document. Otherwise it looks like no groups are selected, so if they select resource groups when they create a document, they will get changed when the document is saved.
            • 3749
            • 24,544 Posts
            It's an interesting idea. If I have time, I'll look into it (unless you'd like to do it). wink
              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