0

So I'm running a hook to update the title with values from the node whenever the node saves. I want to update part of it with a taxonomy term but when I try to get the term from the entity it says it doesn't exist. The field name for the taxonomy term is field_sport but $entity->get('field_sport')->value comes up as doesn't exist. If I do $entity->get('field_first_name')->value it works fine.

    function module_functions_node_presave(Drupal\Core\Entity\EntityInterface $entity) {
  \Drupal::logger('module_functions')->info('field sport ---> ' . $entity->get('field_sport')->value);

  if ($entity->getType() == 'athlete_profile') {
      $entity->setTitle($entity->get('field_first_name')->value. " " . $entity->get('field_maiden_name')->value. " " . $entity->get('field_last_name')->value. " - " . $entity->get('field_sport')->value);

  } 

The first name and last name are just text inputs. Is there something different you need to do to get the taxonomy term?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.