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.
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,
];
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:
- iconset : IconsetSelector
- icons: IconSelect
- ex_icons : ExIconSelect
- iconify_icons : IconifyIcons
- micon (icomoon) : Micon
- md_fontello : MDIcon
- 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.