I am working on a redesign for a site that is implemented using Drupal 8. As part of this redesign, I need to add a taxonomy field to an existing (custom) content type. While I've found a lot of good information related to this problem, I'm afraid I haven't been able to solve it.
Specifically, the site has a content type called audio_recording, which has a number of fields already defined. As part of the redesign, I have created a new taxonomy called topic. The thing I am hung up on is this: how can I make it so that nodes of type audio_recording can be tagged with terms from the topic taxonomy? My understanding is that I need to define an entity reference field on audio_recording, where the reference is to the topic taxonomy. However, I don't know how to do this.
This problem is easily solvable using the GUI (by simply adding a taxonomy field to the content type as usual). And if need be, I can go that route.
But I have written most of the details of the redesign as a series of drush commands, to make it easy for various stakeholders to apply the new design to local dev environments, etc. So it would be great if I could figure out how to create that entity reference field programmatically. Any help would be much appreciated.
Comments
3041571-adding entity reference fields
You can use Configuration API. Just add reference field in your content type and do the required configuration using GUI. Then goto configuration config/development/configuration/single/export and just export all your files related to your content type.
Update/place these files in your config/install folder of the module where you have already created the content type.
you will get your required content type and reference field when you install your module again