Taxonomy field render in custom form

Created on 6 February 2020, almost 5 years ago
Updated 22 January 2022, almost 3 years ago

I have a 3 level deep taxonomy bundle which I want to use it as a select field in a custom form. I could not find any examples of how I can render the field in my custom form, I am able to get if I set "#type" as "entity_autocomplete". But it needs to be a select dropdown. Can anyone give an idea of how I can fix this?

💬 Support request
Status

Closed: outdated

Version

9.4

Component
Taxonomy 

Last updated 35 minutes ago

  • Maintained by
  • 🇺🇸United States @xjm
  • 🇬🇧United Kingdom @catch
Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇮🇳India subhojyoti Kolkata

    $form['my_taxonomy_reference_field'] = [
    '#type' => 'entity_autocomplete',
    '#target_type' => 'taxonomy_term',
    '#title' => $this->t('Country'),
    '#default_value' => '',
    '#selection_settings' => [
    'target_bundles' => ['your_taxonomy_term_machineid'],
    ],
    ];

Production build 0.71.5 2024