0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-11-25 10:40:28 +01:00

Move action callbacks to action class

Dieser Commit ist enthalten in:
Angus McLeod 2022-09-23 16:52:55 +02:00
Ursprung 26749bd055
Commit aa288b19e2
2 geänderte Dateien mit 14 neuen und 9 gelöschten Zeilen

Datei anzeigen

@ -43,10 +43,14 @@ class CustomWizard::Action
@mapper ||= CustomWizard::Mapper.new(user: user, data: mapper_data) @mapper ||= CustomWizard::Mapper.new(user: user, data: mapper_data)
end end
def callbacks_for(action)
self.class.callbacks[action] || []
end
def create_topic def create_topic
params = basic_topic_params.merge(public_topic_params) params = basic_topic_params.merge(public_topic_params)
CustomWizard::Field.action_callbacks.each do |acb| callbacks_for(:before_create_topic).each do |acb|
params = acb.call(params, @wizard, @action, @submission) params = acb.call(params, @wizard, @action, @submission)
end end
@ -421,6 +425,15 @@ class CustomWizard::Action
end end
end end
def self.callbacks
@callbacks ||= {}
end
def self.register_callback(action, &block)
callbacks[action] ||= []
callbacks[action] << block
end
private private
def action_category def action_category

Datei anzeigen

@ -131,10 +131,6 @@ class CustomWizard::Field
} }
end end
def self.action_callbacks
@acbs ||= []
end
def self.require_assets def self.require_assets
Rails.logger.warn("Custom Wizard field regisration no longer requires asset registration. Support will be removed in v2.1.0.") Rails.logger.warn("Custom Wizard field regisration no longer requires asset registration. Support will be removed in v2.1.0.")
@ -153,9 +149,5 @@ class CustomWizard::Field
types[type.to_sym] ||= {} types[type.to_sym] ||= {}
types[type.to_sym] = opts[:type_opts] if opts[:type_opts].present? types[type.to_sym] = opts[:type_opts] if opts[:type_opts].present?
end end
if opts[:action_callback].present? && opts[:action_callback].is_a?(Proc)
action_callbacks << opts[:action_callback]
end
end end
end end