Skip to content

Instantly share code, notes, and snippets.

@travisbutterfield
Last active July 24, 2018 00:24
Show Gist options
  • Save travisbutterfield/b7072888d8566d1b9bda01c1edf866cd to your computer and use it in GitHub Desktop.
Save travisbutterfield/b7072888d8566d1b9bda01c1edf866cd to your computer and use it in GitHub Desktop.
An example of the code to place in a custom module for limiting access to a specific content type, in this case the "custom content type" content type.
<?php
/**
* Implement hook_node_access().
*/
// Add perms to the custom_content_type content type
function HOOK_node_access($node, $op, $account) {
$type = is_string($node) ? $node : $node->type;
if ($type == 'custom_content_type' && $op == 'view') {
// Define roles that can see custom_content_type content type content.
global $user;
$custom_content_type_perms = array_intersect(
array(
'role1',
'role2',
'role3'
),
array_values($user->roles));
// If they have any of these roles, then they can see the custom_content_type content
if ($custom_content_type_perms){
return NODE_ACCESS_ALLOW;
}
else {
return NODE_ACCESS_DENY;
}
}
return NODE_ACCESS_IGNORE;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment