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
|
2024-10-16 13:52:03 +02:00
|
|
|
cw_fields.each { |field| fields << field[:name] } if cw_fields.any?
|
2020-11-09 07:50:17 +01:00
|
|
|
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
|