1

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?

2

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

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

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

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.