1 system.api.php hook_icon_info()

Provides reusable icons from a module.

Backdrop core provides an SVG-based icon system. The default set of icons can be found in /core/misc/icons. Modules may use this hook to provide new icons or to override existing ones provided by core. If creating new, module-specific icons, it's recommended to namespace the icon file with the name of your module. For example, if your module was named "my_module" as was providing a "bird" icon, the icon name should be "my-module-bird". Icon names generally use hyphens, not underscores, in their names.

@since 1.28.0 Hook added.

Return value

array: An array keyed by the icon name. The icon name is used in calls to the icon() function. Optionally providing the following nested array values:

  • name: (optional) If the module-provided icon name differs from the core name, specify the file name minus the ".svg" extension.
  • directory: (optional) If the icon resides outside of the module's "icons" directory, specify the directory from which this icon is provided, relative to the Backdrop installation root.

See also

hook_icon_info_alter()

Related topics

File

core/modules/system/system.api.php, line 471
Hooks provided by Backdrop core and the System module.

Code

function hook_icon_info() {
  // For icons simply located in a module's "icons" directory, just provide the
  // name of the file (minus ".svg") as the array key. This can be used to
  // override core icons if the name of the icon matches a core one, or provide
  // new ones if the name is unique.
  $icons['my-module-icon1'] = array();

  // If a module is overriding a core-provided icon but the module uses a
  // different name, it can specify the core name as the key and provide a
  // "name" property to map to the module's icon file name (minus .svg).
  $icons['pencil'] = array(
    'name' => 'pen',
  );

  // A module could use an externally provided list of icons by specifying
  // a "directory" property, relative to the root of the Backdrop installation.
  $icons['my-module-icon2'] = array(
    'directory' => 'libraries/my_icon_set/standard',
  );

  // If a module wants to separate icons into different directories for
  // variations, it can use the "directory" option to use the same icon name in
  // different directories. For example, this would map
  //"pencil-filled" to "icons/filled/pencil.svg".
  $module_path = backdrop_get_path('module', 'my_module');
  $icons['pencil-fill'] = array(
    'name' => 'pencil',
    'directory' => $module_path . '/icons/filled',
  );

  return $icons;
}