mirror of
https://github.com/discourse/discourse.git
synced 2025-05-28 13:51:18 +08:00
FEATURE: theme_modifiers can depend on theme settings (plus serialize_post_user_badges) (#29227)
Theme modifiers can now be defined as theme settings, this allows for site operators to override behavior of theme modifiers. New syntax is: ``` { ... "modifiers": { "modifier_name": { "type": "setting", "value": "setting_name" } } } ``` This also introduces a new theme modifier for serialize_post_user_badges. Name of badge must match the name of the badge in the badges table. The client-side is updated to load this new data from the post-stream serializer. Co-authored-by: David Taylor <david@taylorhq.com>
This commit is contained in:
@ -297,10 +297,12 @@ class RemoteTheme < ActiveRecord::Base
|
||||
end
|
||||
|
||||
ThemeModifierSet.modifiers.keys.each do |modifier_name|
|
||||
theme.theme_modifier_set.public_send(
|
||||
:"#{modifier_name}=",
|
||||
theme_info.dig("modifiers", modifier_name.to_s),
|
||||
)
|
||||
value = theme_info.dig("modifiers", modifier_name.to_s)
|
||||
if Hash === value && value["type"] == "setting"
|
||||
theme.theme_modifier_set.add_theme_setting_modifier(modifier_name, value["value"])
|
||||
else
|
||||
theme.theme_modifier_set.public_send(:"#{modifier_name}=", value)
|
||||
end
|
||||
end
|
||||
|
||||
if !theme.theme_modifier_set.valid?
|
||||
@ -383,6 +385,8 @@ class RemoteTheme < ActiveRecord::Base
|
||||
self.transaction(&transaction_block)
|
||||
end
|
||||
|
||||
theme.theme_modifier_set.save! if theme.theme_modifier_set.refresh_theme_setting_modifiers
|
||||
|
||||
self
|
||||
ensure
|
||||
begin
|
||||
|
Reference in New Issue
Block a user