lib/scrivito/basic_widget.rb in scrivito_sdk-0.16.0 vs lib/scrivito/basic_widget.rb in scrivito_sdk-0.17.0
- old
+ new
@@ -101,13 +101,15 @@
def obj_class_name
data_from_cms.value_of('_obj_class')
end
+ # Returns the {Scrivito::ObjClass} of this widget.
+ # @return [Scrivito::ObjClass]
+ # @api public
def obj_class
- raise ScrivitoError, "BasicWidget#obj_class is no longer available"+
- ", please use BasicWidget#obj_class_name instead."
+ ObjClass.find(obj_class_name)
end
def ==(other)
other.respond_to?(:obj) && obj == other.obj && other.respond_to?(:id) && id == other.id
end
@@ -119,23 +121,23 @@
# Reverts content changes of this widget. Widget attributes of this widget are not effected.
# After calling this method it's as if this widget has been never modified in the current working copy.
# This method does not work with +new+ or +deleted+ widgets.
# This method also does also not work for the +published+ workspace or the +rtc+ working copy.
def revert
- Workspace.current.assert_revertable
+ workspace.assert_revertable
case modification
when Modification::UNMODIFIED
# do nothing
when Modification::EDITED
previous_obj_content =
- CmsRestApi.get("revisions/#{Workspace.current.base_revision_id}/objs/#{obj.id}")
+ CmsRestApi.get("revisions/#{workspace.base_revision_id}/objs/#{obj.id}")
previous_widget_content = previous_obj_content["_widget_pool"]["#{id}"]
previous_widget_content.delete_if do |attribute_name, _|
type_of_attribute(attribute_name) == "widget"
end
- CmsRestApi.put("workspaces/#{Workspace.current.id}/objs/#{obj.id}",
+ CmsRestApi.put("workspaces/#{workspace.id}/objs/#{obj.id}",
{ obj: {_widget_pool: {id => previous_widget_content}} })
else
raise ScrivitoError, "cannot revert changes, since widget is #{modification}."
end
end
@@ -229,9 +231,17 @@
def description_for_editor
obj_class_name
end
private
+
+ def workspace
+ if revision.workspace
+ revision.workspace
+ else
+ raise ScrivitoError, "No workspace set for the obj of this widget"
+ end
+ end
def data_from_cms
if persisted?
super
else