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

Markdown

  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd>
  • Missing filter. All text is removed
CAPTCHA This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.