Skip to content

Instantly share code, notes, and snippets.

@skounis
Created August 27, 2020 09:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save skounis/d23a76a5225ce0795bdb9f20525a8973 to your computer and use it in GitHub Desktop.
Save skounis/d23a76a5225ce0795bdb9f20525a8973 to your computer and use it in GitHub Desktop.
To extract the field value in Drupal 8
// We can go the long way
$field = $group->some_field->first();
// then
$reference_entity_id = $field->getValue()['target_id'];
// But there is a better way to do it
$reference_entity_id = $group->some_field->target_id;
// The same way we can extract simple types, like string and integer
$field_value = $group->some_field->value;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment