]> source.dussan.org Git - redmine.git/commitdiff
Allows plugins to add custom SVG icons for menu items added by the plugin (#23980).
authorMarius Balteanu <marius.balteanu@zitec.com>
Sun, 10 Nov 2024 15:54:34 +0000 (15:54 +0000)
committerMarius Balteanu <marius.balteanu@zitec.com>
Sun, 10 Nov 2024 15:54:34 +0000 (15:54 +0000)
Patch by Takenori TAKAKI (user:takenory).

git-svn-id: https://svn.redmine.org/redmine/trunk@23234 e93f8b46-1217-0410-a6f0-8f06a7374b81

lib/redmine/menu_manager.rb
test/unit/lib/redmine/menu_manager/menu_helper_test.rb
test/unit/lib/redmine/menu_manager/menu_item_test.rb

index e342add0b768a4133f2dd95e4e8f05fe1218ceeb..5d14fc1f4140827b367e647748aa56537d99bf2f 100644 (file)
@@ -182,7 +182,7 @@ module Redmine
         end
 
         label = if item.icon.present?
-                  sprite_icon(item.icon, h(caption))
+                  sprite_icon(item.icon, h(caption), plugin: item.plugin)
                 else
                   h(caption)
                 end
@@ -431,7 +431,7 @@ module Redmine
     class MenuItem < MenuNode
       include Redmine::I18n
       attr_reader :name, :url, :param, :condition, :parent,
-                  :child_menus, :last, :permission, :icon
+                  :child_menus, :last, :permission, :icon, :plugin
 
       def initialize(name, url, options={})
         if options[:if] && !options[:if].respond_to?(:call)
@@ -461,6 +461,7 @@ module Redmine
         @parent = options[:parent]
         @child_menus = options[:children]
         @last = options[:last] || false
+        @plugin = options[:plugin]
         super(@name.to_sym)
       end
 
index 3d95701823876a0a02acfd2be875088cbf59d43f..4b6151c9d51d61fdfb549232127a66f954021c8d 100644 (file)
@@ -42,6 +42,17 @@ class Redmine::MenuManager::MenuHelperTest < Redmine::HelperTest
     assert_select("a.testing", "This is a test")
   end
 
+  def test_render_single_menu_node_with_plugin_icon
+    node = Redmine::MenuManager::MenuItem.new(:testing, '/test', { :icon => 'plugin_icon_name',:plugin => 'test_plugin_name' })
+    @output_buffer = render_single_menu_node(node, 'This is a test', node.url, false)
+
+    assert_select("a.testing", "This is a test") do
+      assert_select("svg.icon-svg") do
+        assert_select("use[href=?]", "/assets/plugin_assets/test_plugin_name/icons.svg#icon--plugin_icon_name")
+      end
+    end
+  end
+
   def test_render_menu_node
     single_node = Redmine::MenuManager::MenuItem.new(:single_node, '/test', {})
     @output_buffer = render_menu_node(single_node, nil)
index 12d6fa2f6f79a600ecf39d035ffd5c1d6272e66f..d5d9cdbde607aca6b279d4c41fb6e6f516114a4c 100644 (file)
@@ -102,6 +102,13 @@ class Redmine::MenuManager::MenuItemTest < ActiveSupport::TestCase
     end
   end
 
+  def test_new_menu_item_should_allow_setting_the_plugin
+    menu_item = Redmine::MenuManager::MenuItem.new(
+      :test_plugin_menu, '/test', {:plugin => 'test_plugin_name'}
+    )
+    assert_equal 'test_plugin_name', menu_item.plugin
+  end
+
   def test_has_children
     parent_item = get_menu_item(:test_menu, :parent)
     assert parent_item.children.present?