Here's an access plugin to provide access/visiblity if a user context is present in a entityreference or user_reference field.

I decided to propose it for inclusion in ctools since it supports both entity_reference and userreference (references). It differs in two lines to support both.

Files: 
CommentFileSizeAuthor
user_in_reference.patch5.01 KBjonhattan
PASSED: [[SimpleTest]]: [MySQL] 121 pass(es). View

Comments

merlinofchaos’s picture

Since neither of these two fields are in core, it's a little tough to justify this being in CTools directly. And since it's supporting multiple reference types, it can't really be in the respective modules. So I'm not really sure what to do about this. It probably stands to be its own module, but then...nobody will find it.

Though realistically, access plugins that work on reference fields are conceptually wrong. The actual context should be loaded via a relationship, and then the access plugin should work directly on the context. Then you wouldn't need this plugin at all; you can just use the 'context exists' plugin instead to see if it loaded a user. Assuming the proper relationship actually exists -- but that really is up to the module that provides the reference field.

I'll leave this for the moment.

jonhattan’s picture

My first attempt was to use a relationship, but I needed to check access over a multivalued field.

AFAIK a relationship can't provide multiple values, isn't it? The only example I've found is terms_from_node.inc, and this is a special case.

DamienMcKenna queued user_in_reference.patch for re-testing.