Feature #43087
openAllow to change icons sprites from theme
0%
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
Updated by Go MAEDA 6 months ago
- File 43087.patch 43087.patch added
Here is a patch generated from icons_helper.rb.
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.
Updated by Marius BĂLTEANU 1 day ago
- File test-for-43087.patch test-for-43087.patch added
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.
Updated by Catirau Mihail about 19 hours ago
Totally agree with Go MAEDA, a fallback mechanism is a good idea.
Updated by Marius BĂLTEANU about 3 hours ago
- File 0001-Allow-to-change-icons-sprite-from-theme-with-a-fallb.patch 0001-Allow-to-change-icons-sprite-from-theme-with-a-fallb.patch added
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_helperby adding theicons.svgto theme fixtures so I decided the stub all the external dependencies. - I cached the icons using
ActionController::Base.cache_storeinstead of using a instance variable (@icons).
Please let me know if you see any better solution.