How to use Icon propType ?

Created on 18 February 2025, about 2 months ago

Problem/Motivation

hi,
I've a question regarding the usage of UI Icons in component as a prop.
I see there is a 'IconPropType' but i dont see how to use that in my component yml.
Nothing in the docs yet , does anyone have guidance ?

Thanks

πŸ’¬ Support request
Status

Active

Version

1.1

Component

Documentation

Created by

πŸ‡§πŸ‡ͺBelgium gregory_visible LiΓ¨ge

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

Comments & Activities

  • Issue created by @gregory_visible
  • πŸ‡«πŸ‡·France pdureau Paris

    Hi Gregory,

    Do you use UI Patterns ? You need to install ui_icons_patterns sub-module.

    In a SDC component, if you have a prop schema like this:

    type: object
    properties:
      pack_id: 
         "$ref": "ui-patterns://identifier"
      icon_id:
        type: string
      settings:
        type: object
    required: ['pack_id', 'icon_id']
     

    Or, more simply, like this:

    "$ref": "ui-patterns://icon"
    

    Your prop will be recognize as an icon and managed by UI Icon (with the icon picker).

    Then, inside the Twig template, you can use the Drupal Core's icon() Twig function with this mapping's values.

    Is it clear?

  • πŸ‡§πŸ‡ͺBelgium gregory_visible LiΓ¨ge

    Merci , C'est bien clair.

    The selection widget is now availlable.
    But i'm having an error on saving ( both with field ui ans Layout builder )

    With layout builder the field widget disapears and there is an waring logged in watchdog :
    Warning : Undefined array key "#prefix" dans Drupal\ui_icons\Element\IconAutocomplete::buildAjaxCallback() (/app/public_html/modules/contrib/ui_icons/src/Element/IconAutocomplete.php ligne 161)

    With field ui ,same warning is logged and the error displayed is
    An exception has been thrown during the rendering of a template (""pack_id" is an invalid render array key. Value should be an array but got a string.").

    Should i open an issue with this ?

  • πŸ‡«πŸ‡·France pdureau Paris
  • πŸ‡«πŸ‡·France pdureau Paris
Production build 0.71.5 2024