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>);

 


Type:
Tip
Tags:
D8