Skip to main content
added payou's suggestion
Source Link

I have an exposed filter that shows products which have multiple entity references. The user should be able to pick some number of entities and the view should show entities containing all those references. In my mind that should mean changing the in operator on the where clause to an all operator.

function hook_views_query_alter(&$view, &$query) {
  if ($view->vid == 7) {
    dpm ($query);
    if (isset($query->where[1]['conditions'][2]['operator'])) {
      $query->where[1]['conditions'][2]['operator'] = 'all';
    }
    dpm ($query);
  }
}

However this seems to have no effect. the operator is changed from the first dpm to the second and it does break if I enter some other value in the all does not change the results. Do I have the wrong operator? Or am I going about this all wrong?

[edit] According to Payou the function should look like

function falk_products_query_products_alter($query) {
  $conditions = &$query->conditions();
  $conditions2 = &$conditions[0]['field']->conditions();
  $conditions3 = &$conditions2[0]['field']->conditions();
  $my_query = &$conditions2[0]['field'];
  $my_conditions = &$my_query->conditions();
  dpm ($my_query->conditions());
  
  if (isset($my_conditions[2])) {
    foreach ($my_conditions[2]['value'] as $target) {
      $my_query->condition($my_conditions[2]['field'], array($target), 'in');
    }
  }
  dpm ($my_query->conditions());
}

Which at the dpm's give me arrays that look good to me but dont work if more than one value is input. enter image description here

I have an exposed filter that shows products which have multiple entity references. The user should be able to pick some number of entities and the view should show entities containing all those references. In my mind that should mean changing the in operator on the where clause to an all operator.

function hook_views_query_alter(&$view, &$query) {
  if ($view->vid == 7) {
    dpm ($query);
    if (isset($query->where[1]['conditions'][2]['operator'])) {
      $query->where[1]['conditions'][2]['operator'] = 'all';
    }
    dpm ($query);
  }
}

However this seems to have no effect. the operator is changed from the first dpm to the second and it does break if I enter some other value in the all does not change the results. Do I have the wrong operator? Or am I going about this all wrong?

I have an exposed filter that shows products which have multiple entity references. The user should be able to pick some number of entities and the view should show entities containing all those references. In my mind that should mean changing the in operator on the where clause to an all operator.

function hook_views_query_alter(&$view, &$query) {
  if ($view->vid == 7) {
    dpm ($query);
    if (isset($query->where[1]['conditions'][2]['operator'])) {
      $query->where[1]['conditions'][2]['operator'] = 'all';
    }
    dpm ($query);
  }
}

However this seems to have no effect. the operator is changed from the first dpm to the second and it does break if I enter some other value in the all does not change the results. Do I have the wrong operator? Or am I going about this all wrong?

[edit] According to Payou the function should look like

function falk_products_query_products_alter($query) {
  $conditions = &$query->conditions();
  $conditions2 = &$conditions[0]['field']->conditions();
  $conditions3 = &$conditions2[0]['field']->conditions();
  $my_query = &$conditions2[0]['field'];
  $my_conditions = &$my_query->conditions();
  dpm ($my_query->conditions());
  
  if (isset($my_conditions[2])) {
    foreach ($my_conditions[2]['value'] as $target) {
      $my_query->condition($my_conditions[2]['field'], array($target), 'in');
    }
  }
  dpm ($my_query->conditions());
}

Which at the dpm's give me arrays that look good to me but dont work if more than one value is input. enter image description here

edited tags
Link
Source Link

hook_views_query_alter all condition

I have an exposed filter that shows products which have multiple entity references. The user should be able to pick some number of entities and the view should show entities containing all those references. In my mind that should mean changing the in operator on the where clause to an all operator.

function hook_views_query_alter(&$view, &$query) {
  if ($view->vid == 7) {
    dpm ($query);
    if (isset($query->where[1]['conditions'][2]['operator'])) {
      $query->where[1]['conditions'][2]['operator'] = 'all';
    }
    dpm ($query);
  }
}

However this seems to have no effect. the operator is changed from the first dpm to the second and it does break if I enter some other value in the all does not change the results. Do I have the wrong operator? Or am I going about this all wrong?