Add form element(s) for Icon API

Created on 7 June 2025, 28 days ago

Problem/Motivation

In Drupal 11.1, we have shipped ✨ Add an icon management API Active without a Form Element in order to test what can be done in contrib first.

We have now 2 form elements built on the Icon API in contrib, from the same module. Other modules implements the Core Icon API but they don't provide (yet) a dedicated Form Element.

icon_autocomplete

Properties:

  • #default_value: (string) Icon value as pack_id:icon_id.
  • #show_settings: (bool) Enable extractor settings, default FALSE.
  • #default_settings: (array) Settings for the extractor settings.
  • #settings_title: (string) Extractor settings details title.
  • #allowed_icon_pack: (array) Icon pack to limit the selection.
  • #return_id: (bool) Form return icon id instead of icon object as default.

Some base properties from FormElementBase:

  • #description: (string) Help or description text for the input element.
  • #placeholder: (string) Placeholder text for the input, default to 'Start typing icon name'.
  • #required: (bool) Whether or not input is required on the element.
  • #size: (int): Textfield size, default 55.

Example:

[
  '#type' => 'icon_autocomplete',
  '#title' => $this->t('Select icon'),
  '#default_value' => 'my_icon_pack:my_default_icon',
  '#allowed_icon_pack' => [
    'my_icon_pack',
    'other_icon_pack',
  ],
  '#show_settings' => TRUE,
];

icon_picker

Properties:

  • #default_value: (string) Icon value as pack_id:icon_id.
  • #show_settings: (bool) Enable extractor settings, default FALSE.
  • #default_settings: (array) Settings for the extractor settings.
  • #settings_title: (string) Extractor settings details title.
  • #allowed_icon_pack: (array) Icon pack to limit the selection.
  • #return_id: (bool) Form return icon id instead of icon object as default.

Some base properties from FormElementBase.

  • #description: (string) Help or description text for the input element.
  • #placeholder: (string) Placeholder text for the input, default to 'Click to select an Icon'.
  • #required: (bool) Whether or not input is required on the element.
  • #size: (int): Textfield size, default 55.

Global properties applied to the parent element:

  • #attributes': (array) Attributes to the global element.

Example:

[
  '#type' => 'icon_picker',
  '#title' => $this->t('Select icon'),
  '#default_value' => 'my_icon_pack:my_default_icon',
  '#allowed_icon_pack' => [
    'my_icon_pack,
    'other_icon_pack',
  ],
  '#show_settings' => TRUE,
];

Other form elements to study

They are not implementing (yet) the Icon API:

  1. iconset : IconsetSelector
  2. icons: IconSelect
  3. ex_icons : ExIconSelect
  4. iconify_icons : IconifyIcons
  5. micon (icomoon) : Micon
  6. md_fontello : MDIcon
  7. iconify_field : IconifyField

Proposed resolution

Add a Form Element for the icon API in Core, maybe inspired by one of those examples.

If possible, let's keep it simple, dependency free, and theme agnostic.

Also, let's notice the Form Elements may be impacted by πŸ“Œ Define form elements from SDC Active the next months/years, so let's manage the callbacks in a way we can move to SDC later.

User interface changes

No, the form element is not used by default in Druapl Core. It will be available for Contrib modules (which will still be able to add their owns).

API changes

Only additions.

✨ Feature request
Status

Active

Version

11.2 πŸ”₯

Component

theme system

Created by

πŸ‡«πŸ‡·France pdureau Paris

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

Comments & Activities

Production build 0.71.5 2024