I am trying to use an conditional OR in my custom module.

hook_views_query_alter(Drupal\Core\Database\Query\AlterableInterface $query)

I get it to work with either one of these conditions set, but not together.

if (isset($query->alterTags['VIENAME'])) {
  $query->condition('draggableviews_structure.entity_id' , NULL, 'IS NULL');
  $query->condition('draggableviews_structure.view_name', 'view_display_name', '=');

How do I set an OR value between them, so if either is true?



You can do this by using orConditionGroup():

$query = \Drupal::entityQuery('map');
  $group = $query->orConditionGroup()
    ->condition('attributes.color', 'red')
    ->condition('attributes.color', 'green');
  $entity_ids = $query
    ->condition('attributes.building_type', 'bikeshed')

Example from https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Entity!Query!QueryInterface.php/function/QueryInterface%3A%3AorConditionGroup/8.2.x

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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