Get select field value inside of a module I have a taxonomy reference field field_location_type with terms: Term A, Term B.

Inside of my custom module, I'm setting up a presave function that will set a hidden field value depending on the term selected in field_location_type.

I'm trying to log the current value of the field just to confirm i'm getting the right one, but there are no values displaying, like ...

function general_entity_presave(Drupal\Core\Entity\EntityInterface $entity) {
    \Drupal::logger('general')-&gt;notice('here: ' . $entity-&gt;field_location_type-&gt;value);
}


How do i get the value of the select field field_location_type?
Update as @berdir suggested in the comments, the best way to get a field value is:

$node-&gt;get('field_location_type')-&gt;target_id 

In addition, you could also use Field::getValue method if you want an array representation.  Something like: 

$entity-&gt;field_location_type-&gt;getValue()[0]['target_id']);


In addition if you need the term name (Option A ) from the id you can do this:

  $tid = $entity-&gt;get('field_location_type')-&gt;target_id;
  $term = \Drupal\taxonomy\Entity\Term::load($tid);
  // $name should have 'option A' or 'option b'
  $name = $term-&gt;getName();


Update: one way to figure out what methods are available  to you is to use xdebug in PhpStorm. If you set a break point after $field = $entity-&gt;field_location_type; you can then type $field-&gt; and then hit ctrl and space the editor will provide suggestions based on the type of $field Here is a screen shot: