1

I have a Doodad content type that has a couple of Entity Reference fields, for example, parentDoodad. Those fields point to other Doodad nodes. When I'm logged in as an Admin, I'm able to use the auto-complete field to set any doodad in the parentDoodad field.

However, if I switch to a different user and create Doodad1 and Doodad 2 (so that I have multiple nodes owned by this user), when I try to use the entity reference field, it won't show me any of my other Doodads.

If I give my non-admin-user the "Bypass content access control" permission, then I'm able to see and choose those other Doodads in the parentDoodad field.

I want users to be able to choose any of their own Doodad nodes. Is it just a matter of configuring certain permissions? How do I let UserA be able to choose from UserA's nodes in that entity reference field?

3 Answers 3

4

You can do it this way.

  1. Create a view to list the nodes of particular type.

    1a. Add a contextual filter of Content: Author Uid and provide default values as USER ID from logged in user

    1b. Add a Entity Reference display to the view.

  2. Now go to the Entity Reference field you have created in your content type and edit it.

    2a. Under Entity selection select the Mode to Views: Filter by an entity reference view then you will get the view you have created above and select it.

    2b. Save the changes.

This way the user will see only the node they created in the reference field. Read More

There is a second way also, you can implement hook_query_entityreference_alter() and alter the query. Read More

0
1

Wolverine's solution will break if an admin is editing the node. The field will then show only nodes the current user (admin) has created.

A better solution is to use "User ID from URL" and check "Also look for a node and use the node author"; that way when content managers are reviewing nodes, the entity reference field will reflect the original author's nodes, rather than the managers' own.

0

if I select {"User ID from URL" and "Also look for a node and use the node author"}: This solution will break if an user is adding a new node. The field will not show any nodes

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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