I am using the following code.

  $user_storage = \Drupal::service('entity_type.manager')->getStorage('user');

    $ids = $user_storage->getQuery()
      ->condition('status', 1)
      ->condition('roles', 'directeur_cr_')
      ->execute();
    $users = $user_storage->loadMultiple($ids);

I want to add a condition that is verified when the role is directeur_cr_ or comptable_cr_.

How can I add this condition?

up vote 2 down vote accepted

You can use orConditionGroup, but the IN operator is a shorthand for OR conditions on the same field:

->condition('roles', ['role1', 'role2'], 'IN')

You can do like this:

  $user_storage = \Drupal::service('entity_type.manager')->getStorage('user');

    $ids = $user_storage->getQuery()
      ->condition('status', 1)
      ->condition('roles', array('directeur_cr_','comptable_cr_'),'IN')
      ->execute();
    $users = $user_storage->loadMultiple($ids);

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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