I would like to provide users with role-A and role-B the ability to edit their own published and unpublished content. I've installed the Content Access Module and seems impossible to make this without coding. Does anyone know how to solve with code?
2 Answers
I am not sure about your exact requirement. If you want to list all contents created by current user with an edit link, my suggestion to make try with views.
- Give Edit Own Content permission to your needed roles for all content types in Home » Administration » People » Permissions.
- Create a view with content of all.
- Add title in fields (or the fields you want).
- If you want to give an edit link , add Content:Edit Link.
- In views contextual filter add Content:Author uid = User ID from logged in user (Refer here).
- Change format to Table (Only title and edit link is there this gives a nice formatting).
Hope this will help you.
-
With this i can provide my actually view with and edit button but it doesn't change the permission. When i click on edit i see You are not authorized...– EmanueleNov 21, 2015 at 10:30
-
Give Edit Own Content permission to needed roles for all content types in Home » Administration » People » Permissions.– AbinNov 21, 2015 at 10:50
-
-
The only way i've found to see the Edit tab is to check the Bypass the control access to content, first check under Node in permissions page... but it's not a really good solution– EmanueleNov 21, 2015 at 11:07
You can try this in your own module:
function MODULE_permission() {
return array(
'edit own unpublished content' => array(
'title' => t('Edit own unpublished content'),
'description' => t('Allow user to edit own unpublished content.'),
),
);
}
function MODULE_node_access($node, $op, $account) {
if (user_access("edit own unpublished content") && $op == "update" && $node->status == 0 && $node->uid == $account->uid) {
return NODE_ACCESS_ALLOW;
}
}
It will add a permission that is applicable to all nodes. If you want to set it for a specific bundle only you will have to expand on it a bit.
-
-
Try on a clean install to assure yourself that it works, then look at module calling order as it may have an effect. Nov 22, 2015 at 12:46