Hello everyone!
I am working on a package containing a helper to automate a few setup tasks, like creating user groups, setting permissions etc.
Currently, I am struggling with the block permissions. Ideally, I would want to allow certain user groups to add a certain selection of blocks.
This is the code I tried:
$groups = [...];
$blockTypeIds = [...];
$pk = Key::getByHandle('add_block');
$pa = AddBlockBlockTypeAccess::create($pk);
foreach ($groups as $group) {
if (!$group) {
continue;
}
$groupEntity = GroupEntity::getOrCreate($group);
$pa->addListItem($groupEntity);
}
foreach ($pa->getAccessListItems() as $item) {
/** @var AddBlockBlockTypeListItem $item */
$item->setBlockTypesAllowedPermission('C');
$item->setBlockTypesAllowedArray($blockTypeIds);
}
$pa->save();
$pt = $pk->getPermissionAssignmentObject();
$pt->assignPermissionAccess($pa);
This adds the permissions for my user groups, though they allow each group to access ALL the blocks instead of the specified ones.
This looks like this under /dashboard/blocks/permissions:
What I’m really looking for is this:
I am not sure why $item→setBlockTypesAllowedArray() has no effect.
Any help on this problem would me much appreciated!

