Project

General

Profile

Actions

Feature #43087

open

Allow to change icons sprites from theme

Added by Catirau Mihail 6 months ago. Updated about 3 hours ago.

Status:
New
Priority:
Normal
Assignee:
-
Category:
Themes
Target version:
Start date:
Due date:
% Done:

0%

Estimated time:
Resolution:

Description

Allow to change icons sprites from themes

It will be great to have a option to replace sprites icons.svg from active theme

module IconsHelper

# ...

  include Redmine::Themes::Helper

  def sprite_source(sprite: DEFAULT_SPRITE, plugin: nil)
    if plugin
      "plugin_assets/#{plugin}/#{sprite}.svg" 
    elsif current_theme && current_theme.images.include?("#{sprite}.svg")
      current_theme.image_path("#{sprite}.svg")
    else
      "#{sprite}.svg" 
    end
  end

  def sprite_icon(icon_name, label = nil, icon_only: false, size: DEFAULT_ICON_SIZE, style: :outline, css_class: nil, sprite: DEFAULT_SPRITE, plugin: nil, rtl: false)
    sprite = sprite_source(sprite: sprite, plugin: plugin)

    # ...
  end

# ...

end

Files

icons_helper.rb (4.04 KB) icons_helper.rb Catirau Mihail, 2025-08-01 14:59
43087.patch (1.01 KB) 43087.patch Go MAEDA, 2025-08-02 09:59
test-for-43087.patch (1.84 KB) test-for-43087.patch Marius BĂLTEANU, 2026-02-03 03:04
0001-Allow-to-change-icons-sprite-from-theme-with-a-fallb.patch (9.03 KB) 0001-Allow-to-change-icons-sprite-from-theme-with-a-fallb.patch Marius BĂLTEANU, 2026-02-04 04:14
Actions #1

Updated by Go MAEDA 6 months ago

Here is a patch generated from icons_helper.rb.

Actions #2

Updated by Marius BĂLTEANU 28 days ago

  • Target version set to 6.1.2

This is useful for themes developer, let’s discuss it for 6.1.2.

Actions #3

Updated by Marius BĂLTEANU 1 day ago

Added tests for this feature.

Go MAEDA, do you think it is safe to deliver this in 6.1.2 or we should move this to 7.0.0?

Actions #4

Updated by Go MAEDA 1 day ago

This change is fully backward compatible with the existing sprite_icon interface, so it is technically safe to include it in a minor release such as 6.1.2.

There is a small risk that theme authors may rely on this behavior and release themes labeled as "Redmine 6.1 compatible," even though they will not work correctly on 6.1.0 or 6.1.1. However, the impact would be limited: instead of the theme's icons.svg, Redmine would simply use the default icons.svg shipped with the core. Because of this limited impact, including this change in 6.1.2 is acceptable.

However, allowing themes to replace the default icons.svg introduces a long-term maintenance concern for theme authors. If a theme provides its own icons.svg, the theme author must continuously track changes to Redmine's built-in icons.svg. Otherwise, icons added in newer Redmine versions, including minor or bugfix releases, will not be displayed when using that theme. This can become a significant burden for theme authors.

From my perspective, it would be preferable to have a fallback mechanism: if a requested icon is not found in the theme's icons.svg, Redmine should fall back to the default icons.svg shipped with the core. This would reduce the impact of outdated theme icons by showing the default icons provided by Redmine when the theme's icons.svg does not yet include newly added icons.

Actions #5

Updated by Catirau Mihail about 19 hours ago

Totally agree with Go MAEDA, a fallback mechanism is a good idea.

Actions #6

Updated by Marius BĂLTEANU about 3 hours ago

I agree that the fallback mechanism is very important, thanks for pointing this out.

Attached is the patch that implements this. Two mentions:
  • I found difficult to test the changes from icons_helper by adding the icons.svg to theme fixtures so I decided the stub all the external dependencies.
  • I cached the icons using ActionController::Base.cache_store instead of using a instance variable (@icons).

Please let me know if you see any better solution.

Actions

Also available in: Atom PDF