drupal 8 get taxonomy term value in node

后端 未结 6 962
既然无缘
既然无缘 2021-02-08 05:36

Drupal\\node\\Entity\\Node Object ( [in_preview] => [values:protected] => Array ( [vid] => Array ( [x-default] =

6条回答
  •  南笙
    南笙 (楼主)
    2021-02-08 06:13

    This is the correct way on how to achieve it

    use Drupal\taxonomy\Entity\Term;
    
    function modulename_node_presave(Drupal\Core\Entity\EntityInterface $entity) {
        switch ($entity->bundle()) {
            case 'programs':
                $term = Term::load($entity->get('field_program_names')->target_id);
                $name = $term->getName();
                $entity->setTitle($name);
                break;
        }
    }
    

提交回复
热议问题