I'm not looking to use Views for this challenge here but simply to add a check for a value of a field on the viewing user's profile and then to select the correct view mode from Display Suite for that node depending on that value. What would I have to do to accomplish this?
1 Answer
Are you looking for code or just the approach? One approach would would be to use HOOK_entity_view_mode_alter(&$view_mode, $context) in a custom module:
- Check that the user is logged in
- Check that the user is viewing the right kind of node
- Load the user and get the profile field value
- Based on the field value, set the view mode ($view_mode = 'custom')
-
Great! I've never created a module of my own but I guess I should be able to work that out. Nov 20, 2013 at 8:49
-
If you're using Drupal often, and don't mind working with PHP, it's totally worth it to learn how to create a module. There are lot's situations where it's the fastest way to solve a problem. Let me know if you want sample code for changing a view mode. Nov 20, 2013 at 17:26