Programmatically create a term reference entity field

An example of programmatically creating a term reference entity field:
$fields[] = BaseFieldDefinition::create('entity_reference')
 ->setLabel(t(<label>))
 ->setDescription(t(<description>))
 ->setRevisionable(TRUE)
 ->setSetting('target_type', 'taxonomy_term')
 ->setTranslatable(TRUE)
 ->setTargetEntityTypeId(<vocabulary machine name>);

 

Add new comment

Plain text

  • No HTML tags allowed.
  • Web page addresses and email addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Of course, the Drupal Community isn't the only place to give back. It's a complex world, and there are as many worthy causes as their are melodies, with most being served by multiple charitable organizations. Here are a few of those that strike a 7th chord with me.