Setting page and sub-page permissions via code in 5.5 and below

Permalink
I've wondered how to do this for awhile. I knew about the $page->assignPermissionSet($xml) method, but that doesn't allow for setting sub-page permissions, IE what kinds of collections users and groups are allowed to add beneath a page. I did some digging today, and it appears there's a $page->updatePermissions($array) function that takes a much more detailed array and uses that. Here's kind of what that array should look like.

Here I'm basically assuming there's a form posting to this script with a few details. It's going to allow the groups "Administrators" and "Page Type Administrators" and then the user who is submitting the form. The user submitting the form is not allowed to delete.

Loader::model("collection_types");
$data = $_POST;
$parent = Page::getByPath($data['cParentID']);
$page_data = array(
     'cName' => $data['cName'],
     'cDescription' => $data['description'],
     'uID' => $data['uID'],
     'cHandle' => $data['handle']);
$ct = CollectionType::getByHandle($data['ctHandle']);
$newPage = $parent->add($ct, $page_data);
$ptaID = Group::getByName("Page Type Administrators")->getGroupID();
$perm = array();
// Overall Permissions 
$perm['cInheritPermissionsFrom'] = "OVERRIDE";
// subpages inherit permissions from this page


I know this is kind of deprecated with the new 5.6 release, but not everyone is using that yet. I'm sure that others will need this kind of functionality as they work on legacy sites.

hereNT