0
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-08-07 13:19:19 +08:00
discourse/lib/validators/emoji_picker_pinned_groups_validator.rb
Steven Chang 07a13cfd47
FEATURE: Add emoji_picker_pinned_groups for pinning groups in the picker (#41881)
This adds the `emoji_picker_pinned_groups` site setting for pinning
emoji groups at the top of the emoji picker list. It accepts both custom
& non custom emoji group names, and can be ordered to preference.

If a custom emoji group is added, and the group is deleted, it will
gracefully ignore the missing group. A validator is included to ensure
the site setting is correct at time of save.

<img width="912" height="228" alt="image"
src="https://github.com/user-attachments/assets/0a832cd9-146d-4d46-b9d1-4e8d4ea3b30d"
/>

<img width="464" height="354" alt="image"
src="https://github.com/user-attachments/assets/2512df0e-035c-457a-bed3-b5d0ac3edc2c"
/>

---------

Co-authored-by: Martin Brennan <martin@discourse.org>
2026-07-22 09:51:15 -07:00

30 lines
638 B
Ruby
Vendored

# frozen_string_literal: true
class EmojiPickerPinnedGroupsValidator
def initialize(opts = {})
@opts = opts
end
def valid_value?(val)
return true if val.blank?
groups = val.split("|").map(&:strip).reject(&:blank?)
valid_groups = Set.new(Emoji.allowed.map(&:group))
invalid = groups.reject { |g| valid_groups.include?(g) }
if invalid.any?
@invalid_groups = invalid
return false
end
true
end
def error_message
I18n.t(
"site_settings.errors.emoji_picker_pinned_groups_invalid",
groups: @invalid_groups.join(", "),
count: @invalid_groups.size,
)
end
end