0

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;
\dpm($dept->field_administrator_e_mail->value);

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;
\dpm($dept->name);
0

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

$host_entity->host_field->entity->remote_field->value

  • 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.