lib/scrivito/basic_obj.rb in scrivito_sdk-1.8.1 vs lib/scrivito/basic_obj.rb in scrivito_sdk-1.9.0.rc1

- old
+ new

@@ -14,11 +14,11 @@ # displayed. # # @note Please do not use {Scrivito::BasicObj} directly # as it is intended as an abstract class. # Always use {Obj} or a subclass of {Obj}. - # @see http://scrivito.com/objects-widgets-classes CMS objects, widgets, and classes + # @see https://scrivito.com/objects-widgets-classes CMS objects, widgets, and classes # @api public # class BasicObj extend ::ActiveSupport::DescendantsTracker @@ -580,24 +580,16 @@ blob_attribute_definition = attribute_definitions['blob'] blob_attribute_definition.present? && blob_attribute_definition.type == 'binary' end # - # When delivering binary objects, this method decides whether the image transformations should - # be applied by default. - # # @api public + # @deprecated Has no effect anymore: Image transformation will be applied if possible. # - # By default, this method returns +false+. - # Override it in subclasses to fit your needs. - # - # @note Only relevant for binary objects - # @see Scrivito::Configuration.default_image_transformation= - # @see Scrivito::Binary#transform - # def apply_image_transformation? - false + Scrivito::Deprecation.warn( + 'Scrivito::BasicObj#apply_image_transformation? is deprecated and has no effect anymore.') end # Returns true if this Obj is the root Obj. # @api public def root? @@ -621,17 +613,17 @@ # +child_order+ attribute. The same sort order is used when rendering navigations using # the {ScrivitoHelper#scrivito_tag_list scrivito_tag_list} helper. # # @return [Array<Obj>] def sorted_toclist - if sortable_toclist? - (child_order & toclist) + (toclist - child_order).sort_by(&:id) - else - toclist - end + sort_toclist(toclist) end + def sorted_toclist_including_deleted + sort_toclist(children_including_deleted.reject(&:binary?)) + end + def sortable_toclist? has_attribute?(:child_order) end # This should be a Set, because it's faster in this particular case. @@ -906,34 +898,10 @@ workspace.api_request(:put, "/objs/#{id}", obj: previous_attributes) reload end end - def restore_widget(widget_id) - Workspace.current.assert_revertable - - return if modification == Modification::UNMODIFIED - if modification == Modification::DELETED - raise ScrivitoError, 'Can not restore a widget inside a deleted obj' - end - - unless widget = in_revision(Workspace.current.base_revision).widgets[widget_id] - raise ResourceNotFound, "Could not find widget with id #{widget_id}" - end - - container = widget.container - if container.kind_of?(BasicWidget) && !widgets[container.id] - raise ScrivitoError, 'Can not restore a widget inside a deleted widget' - end - - widget_copy = widget.copy_for_restore(read_widget_pool.keys) - attribute_name = widget.container_attribute_name - current_container = widgets[container.id] || self - current_container.update(attribute_name => - current_container[attribute_name].insert(widget.container_attribute_index, widget_copy)) - end - def mark_resolved workspace.api_request(:put, "/objs/#{id}", obj: {_conflicts: nil}) reload end @@ -992,9 +960,21 @@ cms_data_for_revision(base_revision) != cms_data_for_revision(published_revision) end private + + def children_including_deleted + workspace.objs.find_by_parent_path_including_deleted(path) + end + + def sort_toclist(unsorted_toclist) + if sortable_toclist? + (child_order & unsorted_toclist) + (unsorted_toclist - child_order).sort_by(&:id) + else + unsorted_toclist + end + end def cms_data_for_revision(revision) return nil unless revision result = CmsBackend.find_obj_data_by(revision, "id", [id])