Drupal is a registered trademark of Dries Buytaert
drupal 11.3.7 Update released for Drupal core (11.3.7)! drupal 11.2.11 Update released for Drupal core (11.2.11)! drupal 10.6.7 Update released for Drupal core (10.6.7)! drupal 10.5.9 Update released for Drupal core (10.5.9)! cms 2.1.1 Update released for Drupal core (2.1.1)! drupal 11.3.6 Update released for Drupal core (11.3.6)! drupal 10.6.6 Update released for Drupal core (10.6.6)! cms 2.1.0 Update released for Drupal core (2.1.0)! bootstrap 8.x-3.40 Minor update available for theme bootstrap (8.x-3.40). menu_link_attributes 8.x-1.7 Minor update available for module menu_link_attributes (8.x-1.7). eca 3.1.1 Minor update available for module eca (3.1.1). layout_paragraphs 2.1.3 Minor update available for module layout_paragraphs (2.1.3). ai 1.3.3 Minor update available for module ai (1.3.3). ai 1.2.14 Minor update available for module ai (1.2.14). node_revision_delete 2.0.3 Minor update available for module node_revision_delete (2.0.3). moderated_content_bulk_publish 2.0.52 Minor update available for module moderated_content_bulk_publish (2.0.52). klaro 3.0.10 Minor update available for module klaro (3.0.10). klaro 3.0.9 Minor update available for module klaro (3.0.9). layout_paragraphs 2.1.2 Minor update available for module layout_paragraphs (2.1.2). geofield_map 11.1.8 Minor update available for module geofield_map (11.1.8).

ex_icons

317 sites Security covered
View on drupal.org

This module creates a bridge between other modules or themes in integrating external-referencing SVG icons defined in sprite sheets into Drupal.

This module provides a visual UI for end users to be able to select icons provided by extensions. This module provides no icons by itself.

Icons as Plugins

Icons are automatically discovered from the icon sheet at module_or_theme/dist/icons.svg and are recorded in Drupal as plugins. A simple example of a file:

<svg>
  <!--
    Recommended to store symbol elements in the defs tag as it is designed to
    store graphical objects that will be used at a later time.
  -->
  <defs>
    <!--
      The `viewBox` attribute should be included on symbols — this module uses
      the attribute to determine the aspect ratio of icons it discovers.
    -->
    <symbol id="triangle" viewBox="0 0 20 20">
      <path d="M0 20l10-20l10 20z"/>
    </symbol>
  </defs>

  <!--
    However this module does not make any considerations about where symbol
    elements are placed (for maximum compatibility with build processes).
  -->
  <symbol id="circle" viewBox="0 0 30 30">
    <circle cx="15" cy="15" r="15"/>
  </symbol>
</svg>

There is a convenience Drush command to clear the definitions cache for these:

$ drush cache-clear ex-icons

Theme element

A theme function called ex_icon can be used as the #theme key to render any icon from the sprite sheet. Use #id key to specify the icon.

$render = [
  '#theme' => 'ex_icon',
  '#id' => 'arrow',
  '#attributes' => [
    'title' => t('Show more'),
    'width' => 25,
  ],
];

If a title attribute is set, then the SVG element will be given a role of img, otherwise it will be presentation. If only one dimension attribute is set and is a unitless number, then the other will be calculated automatically from the source icon's viewBox attribute. This is to size the SVG more closely to its content, otherwise the browser will default the SVG's dimensions to 300 × 150 pixels.

Twig function

Similar format as the theme element for use inline in twig templates. First argument is the icon ID and the second is a hash of any attributes (optional).

{{ ex_icon('shopping-cart', { height: 20 }) }}

Form element

An icon selection form element to allow picking of an icon graphically.

$form['icon'] = [
  '#type' => 'ex_icon_select',
  '#title' => $this->t('Accompanying icon'),
  '#default_value' => $this->getSetting('icon'),
];

Field API integration

Type Label Description Type Icon Stores an icon's ID as a string value. Widget Icon select Uses the icon form select element to select icon value(s). Formatter Icon Display an icon. Works with Icon as well as string field types. Formatter Link as icon Display a link field as an icon instead of text.

Ecosystem Integrations

Activity

Total releases
1
First release
Jun 2025
Latest release
10 months ago
Release cadence
Stability
100% stable

Releases

Version Type Release date
8.x-1.8 Stable Jun 2, 2025