In my user entity, I have a term reference. In that vocabulary, I have a regular field. How can I fetch that field's value? I tried the below in devel/php to no avail.

$user = Drupal\user\Entity\User::load(17);
$dept = $user->field_department->entity;

My end goal is to send the email to the department's administrator when a user is created.

UPDATE: I also tried the below:

$user = Drupal\user\Entity\User::load(17);
$dept = $user->field_department;

Your missing link is the entity function, which returns the referenced entity object:


  • I tried entity as well, no luck - updating question – Kartagis Jun 14 at 7:27
  • It wasn't working because of the way I added the taxonomy term to the entity. It works correctly now, thanks. – Kartagis Jun 14 at 7:44

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.