Help please programmatically assigning user group permissions to block types.
I have no problems assigning my user groups to the permission key 'add_block' because it's similar to what I've been doing all along, but I am now tripping over CUSTOM assigning which block types user groups I've added can add. I need to curate this list, there are several block types we don't want to give these groups access to.
I've been trying to follow the plumbing and I landed on this in the class list:
Ultimately I will have several block types to assign but just in testing I've been using the "content" block only which is going to be reflected below in my code snippet. I'm also excluding the defined use statements at the top of my controller here for brevity but they are there.
Although I've tried a handful of things and ways, my last attempt looks like this:
$ag = GroupPermissionAccessEntity::getOrCreate(Group::getByName('Administrators')); $bt = BlockType::getByHandle('content'); $btID = $bt->getBlockTypeID(); $abbt = new AddBlockBlockTypeListItem(); $abbt->setAccessEntityObject($ag); $abbt->setBlockTypesAllowedPermission('C'); $abbt->setBlockTypesAllowedArray(array($btID));
I do not get an error when running this but I don't get what I expect to see when I check in the dashboard to see if it has had any affect. See attached screenshot for what I would expect to see in the dashboard... but in words, I expect Custom to be chosen in the select field below my Administrator's group and the Content block to be checked off in the list.
Any help here is appreciated, thanks!