public function populateTaxonomyTermField($field_name, $vid) {
    $item = $this->item;
    $terms = [];
    if (!empty($item[$field_name])) {
      $data = $this->loadDataArray('taxonomy');

      foreach ($item[$field_name] as $k => $value) {
        if (!empty($data[$value])) {
          $name = $data[$value]['name'];
          $entities = $this->loadEntitiesByProperties('taxonomy_term', ['name' => $name, 'vid' => $vid]);

          foreach ($entities as $entity) {
            $terms[] = ['target_id' => $entity->id()];
          }
        }
      }
      return $terms;
    }
  }
public function populateTaxonomyTermField($field_name, $vid) {
    $item = $this->item;
    $terms = [];
    if (!empty($item[$field_name])) {
      $data = $this->loadDataArray('taxonomy');

      foreach ($item[$field_name] as $k => $value) {
        if (!empty($data[$value])) {
          $name = $data[$value]['name'];
          $entities = $this->loadEntitiesByProperties('taxonomy_term', ['name' => $name, 'vid' => $vid]);

          foreach ($entities as $entity) {
            $terms[] = ['target_id' => $entity->id()];
          }
        }
      }
      return $terms;
    }
  }
public function populateTaxonomyTermField ( $ field_name , $ vid ) { $ item = $ this -> item ; $ terms = [ ] ; if ( ! empty ( $ item [ $ field_name ] ) ) { $ data = $ this -> loadDataArray ( 'taxonomy' ) ; foreach ( $ item [ $ field_name ] as $ k => $ value ) { if ( ! empty ( $ data [ $ value ] ) ) { $ name = $ data [ $ value ] [ 'name' ] ; $ entities = $ this -> loadEntitiesByProperties ( 'taxonomy_term' , [ 'name' => $ name , 'vid' => $ vid ] ) ; foreach ( $ entities as $ entity ) { $ terms [ ] = [ 'target_id' => $ entity -> id ( ) ] ; } } } return $ terms ; } }
Finds taxonomy terms by name and vid.

@param string $field_name
Field name.
@param string $vid
Taxonomy vid.

@return array
Returns media entities.
Finds taxonomy terms by name and vid .