getvalue() of multiple values field return only the first value I added a new field in the field manage user page. This is a sample integer multivalue field. (we can enter several integer) 

I edited the profile of the admin user. I added (and save) some values in this field : 

42
66
23
77


In a custom module, I load the current user and I want display all values of my integer multivalue field : 

// Load the current user.
$user = \Drupal\user\Entity\User::load(\Drupal::currentUser()-&gt;id());

// Get field data from that user.
$mycustomfield = $user-&gt;get('field_mycustomfield');


but when I print $mycustomfield->getValue(), I get only the first value : 

// Display values
kint($mycustomfield-&gt;getValue()); // return only 42, but I want get 42, 66, 23, 77


How can I get ALL values of a custom field ?

Thanks :)

EDIT

I try this ... 

// Load the current user.
$user = \Drupal\user\Entity\User::load(\Drupal::currentUser()-&gt;id());

// Set and save field data from that user.
$user-&gt;get('field_mycustomfield')-&gt;setValue(array(1,2,3,4,5));
$user-&gt;save();


// And display
$user = \Drupal\user\Entity\User::load(\Drupal::currentUser()-&gt;id());
$user_mycustomfield = $user-&gt;get('field_mycustomfield')-&gt;getValue();

kint($user_mycustomfield); // print array(1.2.3.4.5) x) 


With a new user, if I set several values from his user profile edit page, getValue() return only the first value

But if I set several values via the api, I can get all values with getValue

It's really strange..
Drupal fields are represented by the ItemList class (whether they're multi-valued or not). The convenience method getValue() iterates through each item's getValue() method to build an array representation of the data value.

To retrieve a string representation of all the items in the list, you can use ItemList::getString(), which iterates through all the list items and calls getString() on each, then implodes them using ", " for glue.

So, for your example:

var_dump($user-&gt;field_mycustomfield-&gt;getString());


will output

string(14) "42, 66, 23, 77"