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.

CommentFileSizeAuthor
user_in_reference.patch5.01 KBjonhattan

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.

chris matthews’s picture

Issue summary: View changes

The 6 year old patch to user_in_reference.inc applied cleanly to the latest ctools 7.x-1.x-dev, but still needs to be officially reviewed and tested by the community.

Checking patch plugins/access/user_in_reference.inc...
Applied patch plugins/access/user_in_reference.inc cleanly.
japerry’s picture

Status: Needs review » Closed (outdated)

Drupal 7 is no longer supported, closing.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.