Help please programmatically assigning user group permissions to block types.

Long story short, I have a ton of sites to manage and they all get the same user groups and permissions structure. I've created a package that will assign permissions. I was cooking right along assigning permissions to pages and setting the task permissions etc.

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();

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!

1 Attachment

View Replies: