How to provide a contextual filter with an OR conjunction to a view? I have users that can be associated with a single node of type foo. The node has a list of users that are associated with it. I populate the entity reference fields in the content type with a view, which filters users that aren't associated with foo (user has no foo). 

What I need to happen is that I need this view to also grab users that are associated with the specific node that I'm looking at, so when I try to add new users to the foo content type, the users that were associated with it beforehand remain associated with it (user has no foo OR user's foo id equals current foo id). The problem is that the first filter is a normal filter, the second is a contextual filter. How can I, programmatically or otherwise, get the views to grab the users I need with those conditions?

Edit: Unfortunately, the views-related hooks aren't called when populating an Entity Reference, which makes things like hook_views_query_alter not a solution. So a more accurate question would be: how can I get the entity reference to grab the users I need with the given conditions?
I guess you need to use hook_views_query_alter and then you could add your OR condition.

function hook_views_query_alter(ViewExecutable $view, QueryPluginBase $query) {
  if ($view-&gt;id() == 'machine_name_of_your_view' ) {
   //$query-&gt;where contains the filter conditions 
   //i.e. 'Where' part of the query where you could add yours.
   var_dump($query-&gt;where);die;
  }
}


more from drupal.org