Use Icon Select widget in custom form

Created on 7 June 2019, over 5 years ago
Updated 27 September 2024, 3 months ago

Hello,
I want to use the "Icon Select" widget in a custom form, but I can't find how to do it.

The purpose is to display the icon selector as when setting the widget in the form display mode from the back office.

Here is the configuration of my field in the form:

use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;

class MyCustomForm extends FormBase {

    public function getFormId()
    {
        return 'my_custom_form_id';
    }

    public function buildForm(array $form, FormStateInterface $form_state)
    {
        // ... other fields ...

        $form['icon_choice'] = [
            '#type' => 'entity_autocomplete',
            '#target_type' => 'taxonomy_term',
            '#selection_settings' => [
              'target_bundles' => [ 'icons' ]
            ]
        ];        

        // ... other fields ...

	return $form;
    }

I found instructions on the web to create a widget and use it from the Drupal back office interface, but I don't think I understood how to do it in programming in the fields of my custom form.

Thank you in advance for your help.

Germain.

💬 Support request
Status

Closed: outdated

Version

1.1

Component

Code

Created by

🇫🇷France Germain Ch.

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.

Production build 0.71.5 2024