2020-11-09 07:50:17 +01:00
|
|
|
module CustomWizardCustomFieldSerializer
|
|
|
|
def attributes(*args)
|
|
|
|
hash = super
|
2021-02-24 08:50:42 +01:00
|
|
|
|
2020-12-01 08:20:02 +01:00
|
|
|
if cw_fields_enabled?
|
|
|
|
@cw_klass = get_cw_class
|
2021-02-24 08:50:42 +01:00
|
|
|
|
2020-12-01 08:20:02 +01:00
|
|
|
if cw_fields.any?
|
|
|
|
cw_fields.each do |field|
|
|
|
|
if @cw_klass == "topic_view"
|
2020-12-04 08:05:56 +01:00
|
|
|
hash[field[:name].to_sym] = object.topic.custom_fields["#{field[:name]}"]
|
2020-12-01 08:20:02 +01:00
|
|
|
else
|
2020-12-04 08:05:56 +01:00
|
|
|
hash[field[:name].to_sym] = object.custom_fields["#{field[:name]}"]
|
2020-12-01 08:20:02 +01:00
|
|
|
end
|
2020-11-09 07:50:17 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2021-02-24 08:50:42 +01:00
|
|
|
|
2020-11-09 07:50:17 +01:00
|
|
|
hash
|
|
|
|
end
|
2021-02-24 08:50:42 +01:00
|
|
|
|
2020-11-09 07:50:17 +01:00
|
|
|
private
|
2021-02-24 08:50:42 +01:00
|
|
|
|
2020-12-01 08:20:02 +01:00
|
|
|
def cw_fields_enabled?
|
|
|
|
SiteSetting.custom_wizard_enabled && CustomWizard::CustomField.enabled?
|
|
|
|
end
|
2020-11-09 07:50:17 +01:00
|
|
|
|
|
|
|
def cw_fields
|
2020-11-09 08:48:55 +01:00
|
|
|
CustomWizard::CustomField.list_by(:serializers, @cw_klass)
|
2020-11-09 07:50:17 +01:00
|
|
|
end
|
2021-02-24 08:50:42 +01:00
|
|
|
|
2020-11-09 07:50:17 +01:00
|
|
|
def get_cw_class
|
|
|
|
self.class.ancestors.map do |klass|
|
|
|
|
klass.to_s.underscore.gsub("_serializer", "")
|
|
|
|
end.select do |klass|
|
|
|
|
CustomWizard::CustomField.serializers.include?(klass)
|
|
|
|
end.first
|
|
|
|
end
|
2021-02-24 08:50:42 +01:00
|
|
|
end
|