We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 40083
    • 3 Posts
    Hi everyone,
    I am thankfull in advance for any help.
    I am using MODX Revolution 2.2.4-pl (advanced).
    I am trying to create member pages. This issue has been raised many times and several users have suggested working solutions (like Bob Ray's tree_root_id solution and the ACL-based resource and user control).
    I have posted my own, ACL-based solution on gist - "own" is actually a gross exaggeration - it is copied-pasted and adapted from several solutions offered by the community (credited in the gist). Be aware though: errors are entirely mine, and I am a non-coder.
    The plugin is fairly simple: on UserFormSave, it creates a corresponding resource, resource group, user group, the necessary access controls and group memberships, and a file directory.

    But how do I assign the created User Group to an existing Form Customization Profile?

    I have tried

    $fields = array( 'usergroup' => 25, 'profile' => 2);
    $FCPUG = $modx->newObject('modFormCustomizationProfileUserGroup', $fields);
    if($FCPUG->save()) {echo 'Success!';}
    

    It does not work. Is it because I can't modify a relationship table?

    Then I tried, without success either:
    $FCPUGs = $modx->getCollection('modFormCustomizationProfileUserGroup');
    $FCprofile = $modx->getObject('modFormCustomizationProfile', 2);
    $FCprofile->addMany($FCPUGs);
    if($FCprofile->save()) {echo 'Success!';}
    

    In the http://bobsguides.com/modx-object-full-reference.html#modFormCustomizationProfile"" target="_blank" rel="nofollow">object reference (thanks to Bob Ray for it) modFormCustomizationProfile objects have a related object UserGroups (from modFormCustomizationProfileUserGroup).
    How do I add one or several User Group to this related object?
    Thank you in advance for your help!

    Update: I see that lukemcd posted the same question on the forum 4 months ago. But he received no answer and posted no solution. [ed. note: marcelliru last edited this post 11 years, 5 months ago.]
      • 23819
      • 37 Posts
      Did you ever find a way to do this?

      I am working on something that requires the exact same thing.

      Cheers
        • 3749
        • 24,544 Posts
        Try it this way:

        // $fields = array( 'usergroup' => 25, 'profile' => 2);
        $FCPUG = $modx->newObject('modFormCustomizationProfileUserGroup');
        $FCPUG->set('usergroup', 23);
        $FCPUG->set('profile', 2);
        if($FCPUG->save()) {echo 'Success!';}



        Some MODX objects won't allow setting fields in the newObject() call.
          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