@@ -42,32 +42,66 @@ public function getConfigTreeBuilder(): TreeBuilder
4242 ->variableNode ('default_icon_attributes ' )
4343 ->info ('Default attributes to add to all icons. ' )
4444 ->defaultValue (['fill ' => 'currentColor ' ])
45+ ->example (['class ' => 'icon ' ])
46+ ->end ()
47+ ->arrayNode ('icon_sets ' )
48+ ->info ('Icon sets configuration. ' )
49+ ->defaultValue ([])
50+ ->normalizeKeys (false )
51+ ->useAttributeAsKey ('prefix ' )
52+ ->arrayPrototype ()
53+ ->info ('the icon set prefix (e.g. "acme") ' )
54+ ->children ()
55+ ->scalarNode ('path ' )
56+ ->info ("The local icon set directory path. \n(cannot be used with 'alias') " )
57+ ->example ('%kernel.project_dir%/assets/svg/acme ' )
58+ ->end ()
59+ ->scalarNode ('alias ' )
60+ ->info ("The remote icon set identifier. \n(cannot be used with 'path') " )
61+ ->example ('simple-icons ' )
62+ ->end ()
63+ ->arrayNode ('icon_attributes ' )
64+ ->info ('Override default icon attributes for icons in this set. ' )
65+ ->example (['class ' => 'icon icon-acme ' , 'fill ' => 'none ' ])
66+ ->normalizeKeys (false )
67+ ->variablePrototype ()
68+ ->end ()
69+ ->end ()
70+ ->end ()
71+ ->end ()
72+ ->validate ()
73+ ->ifTrue (fn (array $ v ) => isset ($ v ['path ' ]) && isset ($ v ['alias ' ]))
74+ ->thenInvalid ('You cannot define both "path" and "alias" for an icon set. ' )
75+ ->end ()
4576 ->end ()
4677 ->arrayNode ('aliases ' )
47- ->info ('Icon aliases (alias => icon name). ' )
48- ->example (['dots ' => 'clarity:ellipsis-horizontal-line ' ])
78+ ->info ('Icon aliases (map of alias => full name). ' )
79+ ->example ([
80+ 'dots ' => 'clarity:ellipsis-horizontal-line ' ,
81+ 'privacy ' => 'bi:cookie ' ,
82+ ])
4983 ->normalizeKeys (false )
5084 ->scalarPrototype ()
5185 ->cannotBeEmpty ()
5286 ->end ()
5387 ->end ()
5488 ->arrayNode ('iconify ' )
55- ->info ('Configuration for the "on demand" icons powered by Iconify.design . ' )
89+ ->info ('Configuration for the remote icon service . ' )
5690 ->{interface_exists (HttpClientInterface::class) ? 'canBeDisabled ' : 'canBeEnabled ' }()
5791 ->children ()
5892 ->booleanNode ('on_demand ' )
59- ->info ('Whether to use the "on demand" icons powered by Iconify.design . ' )
93+ ->info ('Whether to download icons "on demand". ' )
6094 ->defaultTrue ()
6195 ->end ()
6296 ->scalarNode ('endpoint ' )
63- ->info ('The endpoint for the Iconify API. ' )
97+ ->info ('The endpoint for the Iconify icons API. ' )
6498 ->defaultValue (Iconify::API_ENDPOINT )
6599 ->cannotBeEmpty ()
66100 ->end ()
67101 ->end ()
68102 ->end ()
69103 ->booleanNode ('ignore_not_found ' )
70- ->info (' Ignore error when an icon is not found. ' )
104+ ->info (" Ignore error when an icon is not found. \n Set to 'true' to fail silently. " )
71105 ->defaultFalse ()
72106 ->end ()
73107 ->end ()
@@ -94,9 +128,25 @@ protected function loadInternal(array $mergedConfig, ContainerBuilder $container
94128 $ loader ->load ('asset_mapper.php ' );
95129 }
96130
131+ $ iconSetAliases = [];
132+ $ iconSetAttributes = [];
133+ $ iconSetPaths = [];
134+ foreach ($ mergedConfig ['icon_sets ' ] as $ prefix => $ config ) {
135+ if (isset ($ config ['icon_attributes ' ])) {
136+ $ iconSetAttributes [$ prefix ] = $ config ['icon_attributes ' ];
137+ }
138+ if (isset ($ config ['alias ' ])) {
139+ $ iconSetAliases [$ prefix ] = $ config ['alias ' ];
140+ }
141+ if (isset ($ config ['path ' ])) {
142+ $ iconSetPaths [$ prefix ] = $ config ['path ' ];
143+ }
144+ }
145+
97146 $ container ->getDefinition ('.ux_icons.local_svg_icon_registry ' )
98147 ->setArguments ([
99148 $ mergedConfig ['icon_dir ' ],
149+ $ iconSetPaths ,
100150 ])
101151 ;
102152
@@ -107,6 +157,7 @@ protected function loadInternal(array $mergedConfig, ContainerBuilder $container
107157 $ container ->getDefinition ('.ux_icons.icon_renderer ' )
108158 ->setArgument (1 , $ mergedConfig ['default_icon_attributes ' ])
109159 ->setArgument (2 , $ mergedConfig ['aliases ' ])
160+ ->setArgument (3 , $ iconSetAttributes )
110161 ;
111162
112163 $ container ->getDefinition ('.ux_icons.twig_icon_runtime ' )
@@ -117,8 +168,10 @@ protected function loadInternal(array $mergedConfig, ContainerBuilder $container
117168 $ loader ->load ('iconify.php ' );
118169
119170 $ container ->getDefinition ('.ux_icons.iconify ' )
120- ->setArgument (1 , $ mergedConfig ['iconify ' ]['endpoint ' ])
121- ;
171+ ->setArgument (1 , $ mergedConfig ['iconify ' ]['endpoint ' ]);
172+
173+ $ container ->getDefinition ('.ux_icons.iconify_on_demand_registry ' )
174+ ->setArgument (1 , $ iconSetAliases );
122175
123176 if (!$ mergedConfig ['iconify ' ]['on_demand ' ]) {
124177 $ container ->removeDefinition ('.ux_icons.iconify_on_demand_registry ' );
0 commit comments