app/models/pageflow/widget.rb in pageflow-15.0.0.beta2 vs app/models/pageflow/widget.rb in pageflow-15.0.0.beta3
- old
+ new
@@ -59,28 +59,34 @@
end
private
def all
- placeholders_by_role
- .merge(defaults_by_role)
- .merge(from_db_by_role)
- .values
+ initial_widgets = placeholders_by_role.merge(defaults_by_role)
+ initial_widgets.merge(from_db_by_role) { |_role_key, old_val, new_val|
+ if old_val.configuration.present?
+ new_val.configuration = {} if new_val.configuration.nil?
+ new_val.configuration = old_val.configuration.merge(new_val.configuration)
+ end
+ new_val
+ }.values
end
def from_db_by_role
Widget.all.index_by(&:role)
end
def defaults_by_role
config.widget_types.defaults_by_role.each_with_object({}) do |(role, widget_type), result|
- result[role] = Widget.new(role: role, type_name: widget_type.name, subject: nil)
+ result[role] = Widget.new(role: role, type_name: widget_type.name,
+ subject: nil,
+ configuration:
+ config.widget_types.default_configuration(role))
end
end
def placeholders_by_role
return {} unless options[:include_placeholders]
-
config.widget_types.roles.each_with_object({}) do |role, result|
result[role] = Widget.new(role: role, type_name: nil, subject: nil)
end
end