Entity form presents all taxonomy terms instead of vocabulary I create entity form and add entity reference taxonomy field, set it as select and specify options, but i get all terms instead of one vocabulary terms.

Any idea how to make it works?

here some code.

$taxonomyStorage = \Drupal::entityTypeManager()-&gt;getStorage('taxonomy_term');
$voc             = $taxonomyStorage-&gt;loadTree("my_vocabulary");

$array = [];

foreach ($terms as $term) {
    $array[] = [
        'tid' =&gt; $term-&gt;tid,
        'name' =&gt; $term-&gt;name
    ];
}

$fields['voc_type'] = BaseFieldDefinition::create('entity_reference')
        -&gt;setLabel(t('Voc Type'))
        -&gt;setDescription(t('Voc tag'))
        -&gt;setSetting('target_type', 'taxonomy_term')
        -&gt;setDisplayOptions('form', [
            'type'    =&gt; 'select',
            'options' =&gt; $array,
            'weight'  =&gt; -6,
        ])
        -&gt;setDisplayConfigurable('form', true);
$fields['voc_type'] = BaseFieldDefinition::create('entity_reference')
    -&gt;setLabel(t('Voc Type'))
    -&gt;setDescription(t('Voc tag'))
    -&gt;setSetting('target_type', 'taxonomy_term')
    -&gt;setDisplayOptions('form', [
        'type'    =&gt; 'select',
        'options' =&gt; $array,
        'weight'  =&gt; -6,
    ])
    -&gt;setDisplayConfigurable('form', true)

    // I think you're missing this:
    -&gt;setSetting('handler', 'default:taxonomy_term')
    -&gt;setSetting('handler_settings', [
      'target_bundles' =&gt; [
        'my_vocabulary' =&gt; 'my_vocabulary'
      ]
    ]);


I don't think you need to manually gather the options and set them like that. The target_bundles setting should take care of that.