0

I added a field collection to the user 'manage field' page, the field machine name is 'houses'. The user may add as many home he want.

This field collection regroup :

- a sample text plain field (the name of the house), the machine name "house_name"
- a sample integer field (the size of the house), the machine name "house_size"

In a custom module, I want check if the current user have a house with a size = 4 (if in collection fields, there is a house with "house_size = 4"), how can I do that via the Drupal 8 Query Api ?

I found several example of Drupal "Query API", but nothing with collections fields..

I can use the function load of the class FieldCollectionItem, but I want use a fastest way for get the information I want.

Thanks you :)

0

Try to query the fields of the FieldCollectionItem with .entity:

 $user_ids = \Drupal::entityQuery('user')
    ->condition('houses.entity.house_size', 4)
    ->execute();

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.