XF 2.2 How to implement a node permission that is valid for all node types?

Kirby

Well-known member
I am trying to implement a node permission that is valid for all node types, but I don't see an easy/sane way to do this:

Each node type has it's own permission group and the permission definition doesn't seem to a allow a single permission to belong to multiple permission groups.

Is there any (intended) way to accomplish this short of overwriting XF\Permissions\NodePermissions::isValidPermission, XF\Permissions\NodePermissions::getFinalPerms and XF\Permissions\NodePermissions::getFinalAnalysisPerms (which seems ugly as the latter ones kinda would have to be overwritten completely) @Chris D @Kier @Mike ?
 
I can't see any other way then extending XF\Permissions\NodePermissions.

From the looks of it; for getFinalPerms/getFinalAnalysisPerms, you just need to mutate $calculated argument being sent to the parent to copy your permission into the expected node type's permission location.

Similar to this code;
PHP:
if (!isset($calculated[$groupId]))
{
   $calculated[$groupId] = [];
}
$calculated[$groupId]['view'] = $calculated['general']['viewNode'];
Probably copying how $groupId is generated.

Would be nice if the $groupId generation bit was in a function, or a hook point for mutating the $calculated set with the $groupId provided. But oh well.
 
From the looks of it; for getFinalPerms/getFinalAnalysisPerms, you just need to mutate $calculated argument being sent to the parent to copy your permission into the expected node type's permission location.
That's what I am doing right now and this works, but as you've pointed out - the groupId calculation would have to be duplicated (which is already a large chunk of the code).

So together with the code to set the value in $calculated I roughly get to the size of the original method - that just doesn't seem nice ;)
 
Top Bottom