Drupal 8+

Blog posts related to Drupal 8, 9, 10 and above.

Setting the Target ID on a Taxonomy Reference Field in Drupal

Recently on a Drupal website, I was tasked with adding a taxonomy reference field to a content type. This taxonomy reference field replaced an existing select list. I was also tasked with writing a script to programmatically assign the value of the existing select field to the new taxonomy reference field.

But how do you programmatically set the value for a taxonomy reference field? It should be pretty straightforward and usually is. Most examples you find online use one of these two methods:

Notes on Building a Drupal 8 Module, With a Little AngularJS

Note: This post was written 3/20/2016 and refers to a block on this site that displayed links to posts on my Drupal 7 site (webmech.biz). Since that Drupal 7 site has now been taken down, the block of Drupal 7 posts discussed below is no longer available. However, the discussion of how I used processed the data from webmech.biz and used AngularJS to display it may still be of interest.