2

From a custom module, I created a new type of content type via the drupal api (using the hook node_info). Thanks that, I can create node of this content type.

I would like allow access to nodes of this content type only for his author. And I want the author have only access to the view page of the node (edit page denied). How can I do that?

In Short: In my custom module, how allow only access to the view node page only the author of the node? The author can only access to the view page of a node created by the author. And, edits pages aren't be accessible for all non-admin users.

  • This is definitely a dup. Not sure what the best target is, though. – mpdonadio Nov 1 '16 at 23:57
1

We need to set permission for doing this. Permission can be done specific to a Role not to a User. Please use below codes. Please update your role name instead of 'New Role' and machine name of your content_type instead of 'your_content_type'.

$role_name = "New Role";
$role_permissions = array(
  'create your_content_type content',
  );

$role = user_role_load_by_name($role_name);
user_role_grant_permissions($role->rid, $role_permissions);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.