I have been trying out the Message module. I am using it to send notifications to users' profiles whenever a node of a certain content type is added (a simple hook_node_insert() in combination with Message::create()). These notifications are displayed in a view block on the user's profile page (this block is an alteration of the base Message View. Let's say these are nodes whose content type is Event, and each of these nodes has a taxonomy term reference field called Event type (e.g. Sports, Conference, Concert, etc.).

Let's say that a user only wants to be notified about events for which the value of the Event type field is Concert. In the user form, I have provided a field which contains checkboxes for all of the different event types (its a list of all of the terms that come from the Event type vocabulary). Whenever a user visits their profile page, they should only see notifications for the event types they've selected.

I haven't been able to find a solution for how to implement this either at message creation or through some sort of view block hook. I am now trying to do it through Views filters/relationships.

To make the long story short, my view block contains a list of Message type entities, each with an event_type field that references a single taxonomy term. Every user entity on the page has a event_notification_preferences field which is basically an array of taxonomy terms selected by the user.

What I would like to do can be explained through an example. Let's say the view contains three messages, each with a different event_type field (Sports, Conference, Concert). The currently logged in user's event_notification_preferences array contains only one reference (to the Concert term).

How can I filter the view to display only those messages whose event_type field is relevant (i.e., it has a corresponding match in the event_notification_preferences array, in this case Concert)? Is this possible?

1 Answer 1


In case it helps someone - I solved the issue by creating a view block of Messages, then I:

  • Added a relationship with the Taxonomy term referenced from the event_type field.
  • Added a relationship with the User using the event_notification_preferences field.
  • Added a contextual filter for User: User ID and got the default value from the currently logged in user.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.