lib/scrivito/basic_obj.rb in scrivito_sdk-0.13.0 vs lib/scrivito/basic_obj.rb in scrivito_sdk-0.14.0
- old
+ new
@@ -50,14 +50,17 @@
# Obj.create(:title => "My Title")
#
# @example Arrays of {String Strings} allow you to set multi enum fields
# Obj.create(:tags => ["ruby", "rails"])
#
- # @example Simply pass an Array of {BasicWidget Widgets} to change a widget field
+ # @example Simply pass an Array of {BasicWidget Widgets} to change a widget field. See {BasicWidget#clone Widget#clone} on how to clone a widget.
# # Add new widgets
- # Obj.create(:widgets => [Widget.new(_obj_class: 'TitleWidget', tite: 'My Title')])
+ # Obj.create(:widgets => [Widget.new(_obj_class: 'TitleWidget', title: 'My Title')])
#
+ # # Add a widget clone
+ # Obj.create(:widgets => [another_obj.widgets.first.clone])
+ #
# # Changing a widget field
# obj.update(:widgets => [obj.widgets.first])
#
# # Clear a widget field
# obj.update(:widgets => [])
@@ -656,28 +659,9 @@
end
def widget_from_pool(widget_id)
widget_data = widget_data_from_pool(widget_id)
instantiate_widget(widget_id, widget_data) if widget_data
- end
-
- def copy_widget_from(src_obj_id, src_widget_id)
- raise "cannot copy widget, since workspace is not modifiable" if Workspace.current.published?
-
- src_obj_content = CmsRestApi.get(cms_rest_api_path(src_obj_id))
- widget_content = src_obj_content["_widget_pool"]["#{src_widget_id}"]
-
- raise "cannot copy widget, since widget does not exist" unless widget_content
-
- src_widget = BasicObj.find(src_obj_id).widget_from_pool(src_widget_id)
- widget_content.delete_if do |attribute_name, _|
- src_widget.type_of_attribute(attribute_name) == "widget"
- end
- widget_pool_id = BasicObj.generate_widget_pool_id
-
- CmsRestApi.put(cms_rest_api_path, obj: {_widget_pool: {widget_pool_id => widget_content}})
-
- widget_pool_id
end
# for internal testing purposes only
def blob_id
find_blob.try(:id)