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 load the current user and get values of all values of all his houses (in an array ?), how can I do that ?
I tried this :
$user = \Drupal\user\Entity\User::load(\Drupal::currentUser()->id());
$user_houses = $user->get('field_houses')->getValue();
ksm($user_houses);
But I get :
It's ok, I set 8 houses in "user edit" page, so I get an array of 8 entries. But, I would like get all data in an array like this :
house 1 : name1 : size1
house 2 : name2 : size2
...
house 8 : name8 : size8
Thank you :)