Quantcast
Channel: Comments on: concrete5 – Working with custom Permission Keys
Viewing all articles
Browse latest Browse all 8

By: Terry SoRelle

$
0
0

Thanks Remo. This seems to be on the right track but still having issues. In my adaptation of the code examples you give and cite. $pk->getPermissionAccessID() returns null, causing $paGlobal = PermissionAccess::getByID($accessId, $pk) also to return null.

Here is my full example

/**
* @param $permissionKey string handle for permission
* @param $roleName string handle for group
* @param bool $delete revoke if true, assign if false, default false
* @return bool
*/
private function assignPermissionGroup( $permissionKey, $roleName,$delete=false)
{
$group = Group::getByName($roleName);
if (empty($group)) {
return false;
}

/**
* @var $pkObject \Concrete\Core\Permission\Key\Key
*/
$pkObject = \Concrete\Core\Permission\Key\Key::getByHandle($permissionKey);

/**
* @var $permissionAssignment \Concrete\Core\Permission\Assignment\Assignment
*/
$permissionAssignment = $pkObject->getPermissionAssignmentObject();

// Error!! $accessId assigned null;
$accessId = $pkObject->getPermissionAccessID();

/**
* @var $paGlobal PermissionAccess
*
* Warning, $paGlobal must be duplicated per the statement below. Any other methods applied will affect all Task permissions.
*/
$paGlobal = PermissionAccess::getByID($accessId, $pkObject);

/**
* @var $permissionAccess PermissionAccess
*/
$permissionAccess = $paGlobal->duplicate();

/**
* @var $groupEntity GroupPermissionAccessEntity
*/
$groupEntity = GroupPermissionAccessEntity::getOrCreate($group);
if ($groupEntity === null) {
return false;
}

if ($delete) {
$permissionAccess->removeListItem($groupEntity);
} else {
$permissionAccess->addListItem($groupEntity);
}

$permissionAssignment->assignPermissionAccess($permissionAccess);
return true;
}


Viewing all articles
Browse latest Browse all 8

Latest Images

Trending Articles





Latest Images