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

    I’m developing a site that will contain news items and events. These are stored as resources within a certain resource container (two actually, one for news items and one for events). I wanted to use MM to streamline the creation of such resources so that only the required fields are displayed to non-administrator users.

    I found a tip on another post for making rules sensitive to the parent id:

    // Hides the field tvname for all docs whose parent isn’t id 28.
    if($content[’parent’] != 28){
    mm_hideFields(’tvname’,’2’);
    }

    from: http://modxcms.com/forums/index.php/topic,40937.msg246803.html#msg246803

    However, that doesn’t work for a resource that has just been created because $content[’parent’] hasn’t been set yet.

    The parent id is obviously known - it is displayed on the resource’s page. So, I tracked down the manager code that generates the display of the resource parent and came up with this extended bit of code:

    $parentId == 0;
    if (isset($_REQUEST[’id’]))
    {
    $parentId = $content[’parent’];
    }
    elseif (isset($_REQUEST[’pid’]))
    {
    $parentId = $_REQUEST[’pid’];
    }

    if($parentId == <id of container>)
    {
    ... conditional rules ...
    }

    So, thought I’d share this with the community ... for two reasons ... someone else might find it useful, and so that experienced MODx developers out there can have a look at it and tell me if its ok smiley

    Cheers,

    Colin