lib/scrivito/obj_data.rb in scrivito_sdk-0.16.0 vs lib/scrivito/obj_data.rb in scrivito_sdk-0.17.0

- old
+ new

@@ -21,10 +21,24 @@ INTERNAL_COMPARISON_KEYS = Set.new(internal_comparison_key_list.map { |name| "_#{name}" }) SPECIAL_KEYS = Set.new(%w[ body title blob ]) + ATTRIBUTE_DEFAULT_VALUES = { + "string" => "", + "text" => "", + "html" => "", + "multienum" => [], + "linklist" => [], + "referencelist" => [], + "widget" => [], + "enum" => nil, + "binary" => nil, + "date" => nil, + "reference" => nil, + "link" => nil, + }.freeze def value_of(attribute_name) value_and_type_of(attribute_name).first end @@ -103,10 +117,15 @@ [default_attribute_value(attribute_name), type] else [ObjData::MissingAttribute.new, nil] end else - value_and_type + value, type = value_and_type + if value.nil? && has_custom_attribute?(attribute_name) + value = ATTRIBUTE_DEFAULT_VALUES[type] + end + + [value, type] end end def type_of_internal(key) case key