Skip to content

[Icons] icon_attributes in config not working #2466

Closed
@AiYoriAoshi

Description

@AiYoriAoshi

I required symfony/ux_icons via composer, imported some icons and put them via ux_icon() in the template.

The icons came out way to big so I looked at the documentation and found that I can set the size directly in the ux_icon() call as second parameter, which works fine. Having to do this for every icon because I want them all the same size seems really redundant, so I checked the documentation again and found default_icon_attributes which is in the config yaml. I noticed that no yaml file was created upon installing the module, so I created it manually. Though the docs were kinda sparse, I just went ahead and tried it with width and height but nothing happend. So I assumed maybe that options are not accepted, so I tried fill which is set in the documentation but alas, nothing happend (well fill: currentColor is default so I set it something else just to see if anything happens).

Showing the config via console debug:config ux_icons outputted default values and values that I changed via the yaml file.

$ symfony console debug:config ux_icons

Current configuration for extension with alias "ux_icons"
=========================================================

ux_icons:
    default_icon_attributes:
        fill: none
        height: 16
        width: 16
        class: svg-img
    iconify:
        enabled: false
        on_demand: true
        endpoint: 'https://api.iconify.design'
    ignore_not_found: true
    icon_dir: /home/user/PhpStormProjects/admin8/assets/icons
    icon_sets: {  }
    aliases: {  }

In PR #2156 I saw that I can set attributes for specific icon_sets so I tried that, but the result stays the same.

#config/packages/ux_icons.yaml
ux_icons:
  default_icon_attributes:
    fill: 'none'
    height: '16'
    width: '16'
    class: 'svg-img'
  iconify:
    enabled: false
  ignore_not_found: true
  icon_sets:
    mdi:
      icon_attributes:
        height: '16'
        width: '16'
        class: 'svg-img'
        fill: 'none'

I started digging into the code and it seems to me, that the function loadInternal in UIIconsExtension.php is never called as when putting some var_dumps into renderIcon function for the attributes reveals empty arrays respectively default attribute values

        var_dump($attributes);
        var_dump($this->defaultIconAttributes);
        var_dump($setAttributes);
        $icon = $icon->withAttributes([...$this->defaultIconAttributes, ...($setAttributes ?? []), ...$attributes]);

Am I doing something wrong?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions