Excluding Guest Access to page programmatically
Permalink
I have programmatically created a page, created a security group, added the current user to the security group and added the security group to View page permissions for the page. I now need to programmatically exclude guests from viewing this page.
This is all going in the controller - function add() - for a custom block. When I try to add the block, I get this error:
"Catchable fatal error: Object of class Group could not be converted to string in /home/content/A/n/n/Annalyzer/html/concrete/libraries/3rdparty/adodb/adodb.inc.php on line 1015"
This is the code I am using:
If I remove this code, it works fine:
I've also tried Group::getByName('Guests') and Group::getByName('Guest'), but they all fail. How do I refer to the Guest group to remove it from this permission?
This is all going in the controller - function add() - for a custom block. When I try to add the block, I get this error:
"Catchable fatal error: Object of class Group could not be converted to string in /home/content/A/n/n/Annalyzer/html/concrete/libraries/3rdparty/adodb/adodb.inc.php on line 1015"
This is the code I am using:
// get current user and page $user = new User(); $parentPage = Page::getCurrentPage(); // create a new security group to administer employment app block and add current user to the group. $grpName = 'EmploymentAppAdmin'.$parentPage->getCollectionId(); $grp = Group::getByName($grpName); if (is_null($grp)) { Group::add($grpName, 'Admin Group for btEmploymentApp block'); } $grp = Group::getByName($grpName); $user->enterGroup($grp); //Add admin page and exclude from navigation $pageType = CollectionType::getByHandle('left_sidebar'); $newPage = $parentPage->add($pageType, array('cName' => 'EmploymentAppAdmin', 'cDescription' => 'Administration page for Employment Application', 'cHandle ' => 'EmploymentAppAdmin')); $newPage->setAttribute('exclude_nav', true);
Viewing 15 lines of 35 lines. View entire code block.
If I remove this code, it works fine:
$removeTheseGroups = array(Group::getByID(GUEST_GROUP_ID)); foreach ($removeTheseGroups as $removeMe) { $pe = GroupPermissionAccessEntity::getOrCreate(Group::getByName($removeMe)); $pa->removeListItem($pe); }
I've also tried Group::getByName('Guests') and Group::getByName('Guest'), but they all fail. How do I refer to the Guest group to remove it from this permission?
You are already getting a group object that you push in the array $removeTheseGroups so your variable $removeMe is already a group, not a group name so you can't call getByName on it.
It should be: