lib/scrivito/attribute_content.rb in scrivito_sdk-0.65.2 vs lib/scrivito/attribute_content.rb in scrivito_sdk-0.66.0.rc1
- old
+ new
@@ -14,21 +14,20 @@
multienum
reference
referencelist
string
stringlist
- widget
widgetlist
]
COMPATIBLE_ATTRIBUTE_TYPES = [
%w[enum string],
%w[html string],
%w[multienum stringlist],
%w[string html],
- %w[string text],
- %w[widgetlist widget],
+ %w[string],
+ %w[widgetlist],
]
#
# @api public
#
@@ -43,24 +42,21 @@
'linklist' => [],
'multienum' => [],
'reference' => nil,
'referencelist' => [],
'string' => '',
+ 'stringlist' => [],
'widgetlist' => [],
}
delegate :attribute_definitions, to: :class
def has_attribute?(attribute_name)
has_public_system_attribute?(attribute_name) || has_custom_attribute?(attribute_name)
end
def has_custom_attribute?(attribute_name)
- if revision.workspace.uses_obj_classes && attribute_definitions.blank? &&
- !self.class.special_class?
- Scrivito.raise_obj_class_deprecated_error
- end
!!attribute_definitions[attribute_name]
end
def read_attribute(attribute_name)
@attribute_cache.fetch(attribute_name) do
@@ -105,27 +101,20 @@
# Each class must be either a +String+, a +Symbol+ or the +Class+ itself.
# Only these classes will be available and their order will be preserved.
#
# @api public
# @param [String] field_name Name of the widget field.
- # @return [nil, Array<Symbol, String, Class>]
+ # @return [nil, Array<Class>]
#
def valid_widget_classes_for(field_name)
end
def valid_widget_ruby_classes_for(field)
- computed_classes = valid_widget_classes_for(field)
+ computed_classes = self.class.assert_classes(valid_widget_classes_for(field),
+ '#valid_widget_classes_for')
- ruby_classes =
- if computed_classes
- type_computer = Widget.type_computer
- self.class.convert_to_obj_classes(computed_classes, type_computer) do |name|
- Rails.logger.warn("Invalid widget class #{name} returned by #valid_widget_classes_for.")
- end
- else
- Scrivito.models.widgets.to_a
- end
+ ruby_classes = computed_classes || Scrivito.models.widgets.to_a
ruby_classes.select { |ruby_class| ruby_class.valid_inside_container?(self.class) }
end
@@ -159,31 +148,10 @@
#
def obj_class_name
data_from_cms.value_of('_obj_class')
end
- #
- # Returns the obj class of this object.
- #
- # @api public
- # @deprecated
- # @see Scrivito::ObjClass.remove
- #
- # @return [Scrivito::ObjClass] if the corresponding workspace still uses {Scrivito::ObjClass}.
- # @return [nil] if the corresponding workspace does not use {Scrivito::ObjClass} anymore.
- #
- def obj_class
- if revision.workspace.uses_obj_classes
- if obj_class_data = CmsBackend.instance.find_obj_class_data_by_name(revision, obj_class_name)
- ObjClass.new(obj_class_data, revision.workspace)
- end
- else
- Scrivito.print_obj_class_deprecated_warning
- nil
- end
- end
-
def find_attribute_containing_widget(widget_id)
attribute_definitions.each do |attribute_definition|
if attribute_definition.widgetlist?
widgetlist_name = attribute_definition.name
widgetlist_value = data_from_cms.value_of(widgetlist_name)
@@ -195,12 +163,11 @@
def referenced_widgets
widgets = []
data_from_cms.attribute_names.each do |attr_name|
- type = data_from_cms.type_of(attr_name)
- if type == "widgetlist" || type == "widget"
+ if data_from_cms.type_of(attr_name) == "widgetlist"
value = data_from_cms.value_of(attr_name) || []
widgets_in_value = value.map { |widget_id| widget_from_pool(widget_id) }
widgets += widgets_in_value
end
end
@@ -320,12 +287,13 @@
# and a model +SpecialPage+ inherits from +Page+, then the model +SpecialPage+ will also have
# the attribute +title+. Inherited attributes can be overridden, e.g. +SpecialPage+ can override
# the inherited attribute +title+ by defining its own +title+ with a different type for example.
#
# @param [Symbol, String] name name of the attribute.
- # @param [Symbol, String] type type of the attribute. Scrivito supports following types: +string+,
- # +html+, +enum+, +multienum+, +widgetlist+, +reference+, +referencelist+ and +binary+.
+ # @param [Symbol, String] type type of the attribute. Scrivito supports following types:
+ # +string+, +stringlist+, +html+, +enum+, +multienum+, +widgetlist+, +reference+,
+ # +referencelist+, +link+, +linklist+ and +binary+.
# @param [Hash] options definition options.
#
# @option options [Symbol, String] :values allowed values for types +enum+ and +multienum+.
# If no values are given for that types, then an empty array will be assumed.
# @option options [Symbol, String] :default custom default value.
@@ -582,19 +550,15 @@
def special_class?
type_computer.special_class?(self)
end
- def convert_to_obj_classes(class_names, type_computer)
- class_names.inject([]) do |classes, class_name|
- begin
- widget_class = type_computer.compute_type_without_fallback(class_name.to_s)
- classes << widget_class
- rescue ObjClassNotFound
- yield class_name
- end
- classes
+ def assert_classes(classes_expected, callback_method_name)
+ if (classes_expected || []).any?{ |a| !a.is_a?(Class) }
+ raise "Overridden method #{callback_method_name} must return actual classes!"
end
+
+ classes_expected
end
protected
def assert_valid_attribute_name(name)