2021-03-11 07:30:15 +01:00
|
|
|
# frozen_string_literal: true
|
2020-11-09 07:50:17 +01:00
|
|
|
module CustomWizardCustomFieldPreloader
|
|
|
|
def preload_custom_fields(objects, fields)
|
2020-12-01 08:20:02 +01:00
|
|
|
if objects.present? && cw_fields_enabled?
|
2020-11-09 07:50:17 +01:00
|
|
|
@cw_klass = objects.first.class.name.underscore
|
|
|
|
if cw_fields.any?
|
|
|
|
cw_fields.each do |field|
|
2020-12-04 08:05:56 +01:00
|
|
|
fields << field[:name]
|
2020-11-09 07:50:17 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
super(objects, fields)
|
|
|
|
end
|
2021-03-11 07:30:15 +01:00
|
|
|
|
2020-12-01 08:20:02 +01:00
|
|
|
def cw_fields_enabled?
|
|
|
|
SiteSetting.custom_wizard_enabled && CustomWizard::CustomField.enabled?
|
|
|
|
end
|
2021-03-11 07:30:15 +01:00
|
|
|
|
2020-11-09 07:50:17 +01:00
|
|
|
def cw_fields
|
2020-11-09 08:48:55 +01:00
|
|
|
CustomWizard::CustomField.list_by(:klass, @cw_klass)
|
2020-11-09 07:50:17 +01:00
|
|
|
end
|
2021-03-11 07:30:15 +01:00
|
|
|
end
|