Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By drupalfriend123 on
Hi,
I created a content type - admin and customrole have access to view. Content type has entity reference field.
I added two users. Both users are members of customrole.
Add content > entity reference = user1 > node/1.
Add content > entity reference = user2 > node/2.
When User1 logs in, he should have only view access to node/1. No access to node/2.
When user2 logs in, he should have only view access to node/2. No access to node/1
Admin should have access to both nodes.
I can do it using view. I am talking how I can do in node level?
Thanks.
Comments
Node Access
Maybe this?
https://www.drupal.org/project/nodeaccess
Re: How to add a content so user can see only their content
Yes, It can done by contextual filter in views.
Views configuration steps:
1. Create a view as required.
2. Add contextual filter "Content: Author uid" and mark on "Provide a default value" on WHEN THE FILTER VALUE IS NOT IN THE URL" and set value User ID from logged in user"
3. Also add EXCEPTIONS on right hand side and "Exception value" = '1' (which says when admin logins, author uid condition will be skipped)
Thanks!