Allow creation of contexts where the conditions are based on values in the Field API fields of the current user object.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

firebird’s picture

Status: Active » Needs work
FileSize
1015 bytes
1.52 KB

Here's a patch that adds a plugin that does exactly that. It's not very refined and there are some @todos left in the code. It does work based on the few cases I've tested.

firebird’s picture

Improved plugin that can handle Term Reference fields as well.

jelo’s picture

Hi firebird,

May I ask you if I get the problem correctly? I have taxonomy reference fields in the user account (/admin/config/people/accounts/fields). Now I am trying to set a context that fires based on the logged in user and the tags as recorded in those taxonomies (condition: taxonomy from user profile). But nothing happens. Is the user object not by default loaded on each node so that context can compare the condition? I don't want this to just happen on the user page, but on any node.

Example:
User profile has a term reference field for country of citizenship. Now I want to present a block to all users from country x. I tried to set a context where condition taxonomy citizenship = country x with reaction to display the block.

Does this patch allow me to do that?

Thanks, J.

firebird’s picture

That's what the patch allows you to do, on any page. The Context plugin loads the user object. I just tested this with a clean install, and it works.

Note that in order to use term reference fields, you need to use the plugin file from comment #2 instead of the original one.

When you're editing your context, you should select Conditions->Add a condition->User field and so on. I can't even see have anything called "Taxonomy from user profile" in my installation.

akumajfr’s picture

FileSize
1.53 KB

I hope you don't mind, but I took the liberty to turn this into a custom module, instead of a patch to Context. From my initial tests, it seems to work just fine! Feel free to publish it out to drupal.org if you like.

namwebs’s picture

Issue summary: View changes

Just to confirm - I have used the module in #5 and it is working, thanks akumajfr.

digitgopher’s picture

#5 works for me also. Thanks!

Note there is a recent sandbox project on this topic https://www.drupal.org/node/2472805.