1 common.inc | backdrop_add_icons(array $icon_names) |
Adds icons to the page to make them available in JS and CSS files.
The icon name is resolved to a file path and then added to the page as both a JavaScript variable (Backdrop.icons['icon-name']) and as a CSS variable (--icon-[icon-name]). Note that use of this function is not necessary if embedding an icon directly onto the page using the icon() function. This is only needed if using icons in JS and CSS files.
@since 1.28.0 Function added.
Parameters
array $icon_names: An array of unique icon names be added, without the extensions. Most icon names can be found by browsing the core/misc/icons directory. The icon list can either be a plain list of names in an unindexed array, or the icon name can be the key, with an array of options as the value. The available options for each icon include:
- immutable: Whether to use the original icon instead of any overrides.
See also
icon()
File
- core/
includes/ common.inc, line 5553 - Common functions that many Backdrop modules will need to reference.
Code
function backdrop_add_icons(array $icon_names) {
$icon_paths = array();
foreach ($icon_names as $icon_key => $icon_options) {
$icon_name = is_array($icon_options) ? $icon_key : $icon_options;
$immutable = is_array($icon_options) && !empty($icon_options['immutable']);
if ($icon_path = icon_get_path($icon_name, $immutable)) {
$icon_paths[$icon_name] = base_path() . $icon_path;
}
}
if ($icon_paths) {
backdrop_add_js(array('icons' => $icon_paths), 'setting');
backdrop_add_library('system', 'backdrop.icons');
}
}