FEATURE: Add new plugin API to allow plugins to extend Site#categories (#13773)

This commit is contained in:
Alan Guo Xiang Tan
2021-07-19 13:54:19 +08:00
committed by GitHub
parent 8de8989576
commit a1047f5ef4
3 changed files with 45 additions and 0 deletions

View File

@@ -7,6 +7,14 @@ class Site
cattr_accessor :preloaded_category_custom_fields
self.preloaded_category_custom_fields = Set.new
def self.add_categories_callbacks(&block)
categories_callbacks << block
end
def self.categories_callbacks
@categories_callbacks ||= []
end
def initialize(guardian)
@guardian = guardian
end
@@ -104,6 +112,11 @@ class Site
end
categories.reject! { |c| c[:parent_category_id] && !by_id[c[:parent_category_id]] }
self.class.categories_callbacks.each do |callback|
callback.call(categories)
end
categories
end
end