Allow creation of contexts where the conditions are based on values in the Field API fields of the current user object.
| Comment | File | Size | Author |
|---|---|---|---|
| #5 | context_user_field.tar_.gz | 1.53 KB | akumajfr |
| #2 | context_condition_user_field.inc_.zip | 1.15 KB | firebird |
| #1 | context-add_user_field_support-1392794-1.patch | 1.52 KB | firebird |
| #1 | context_condition_user_field.inc_.zip | 1015 bytes | firebird |
Comments
Comment #1
firebird commentedHere'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.
Comment #2
firebird commentedImproved plugin that can handle Term Reference fields as well.
Comment #3
jelo commentedHi 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.
Comment #4
firebird commentedThat'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.
Comment #5
akumajfr commentedI 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.
Comment #6
namwebs commentedJust to confirm - I have used the module in #5 and it is working, thanks akumajfr.
Comment #7
digitgopher commented#5 works for me also. Thanks!
Note there is a recent sandbox project on this topic https://www.drupal.org/node/2472805.