Problem/Motivation

Since Drupal 11.1, the Icon API was introduced in Drupal - https://www.drupal.org/docs/develop/drupal-apis/icon-api
For a project I have used this API to define a set of icons that can be used within the project.

In a custom field, I'd like to add an icon subfield.
Currently I have implemented this by using the ui_icons module with a couple of its submodules.
I create a new Media type "Icon" to reference the appropriate icon, and in the custom field I create an entity reference to the "Icon" media entities. This does get the job done.

It feels like a workaround however, in that I always have to create an icon media entity instance, before it can be used within the custom field, so from an editorial point of view, it's not really user friendly.

Not sure how technically complex it would be, but it would be nice if I could reference an icon from an icon pack directly within a custom field subfield.

This probably would have to be added in a submodule, which is only installable on Drupal 11.1+, since the Icon API is not available on older Drupal versions, which might complicate things further.

Comments

svendecabooter created an issue.

apmsooner’s picture

Sounds like what you're wanting is in the example here: https://git.drupalcode.org/project/ui_icons/-/tree/1.1.x/modules/ui_icon...

svendecabooter’s picture

Yes I'm aware of the ui_icons field type... but I can't use that within a custom field, can I?
E.g. have a custom field containing icon & text subfields, with cardinality unlimited, to have a repeated icon + text item list.
Or am I missing something?

apmsooner’s picture

No, I was just saying that seems like the structure we can adapt for custom_field.

svendecabooter’s picture

Ah yes I see... that seems correct.