Sha256: e17745d648ab5ede0485ed1997c71c1f99d42dae9a147adbdcd7cb81a6043092

Contents?: true

Size: 1.29 KB

Versions: 19

Compression:

Stored size: 1.29 KB

Contents

require 'fiona7/attribute_writers/attribute_writer'

module Fiona7
  module AttributeWriters
    class WidgetlistAsLinklist < AttributeWriter
      def call(value, claimed_type=nil)
        # TODO: widget_respository
        links = []
        if value.kind_of?(Array)
          (value || []).each do  |widget_id|
            if (path=self.widget_map[widget_id]||self.widget_map[widget_id.to_s])
              links << {destination_object: path, title: widget_id}
            else
              raise Scrivito::ScrivitoError, "Inconsistent widget pool state detected, unable to store widgets (unable to find #{widget_id} in #{self.widget_map.inspect})"
            end
          end
        elsif value.kind_of?(Hash)
          # stupid shits could not use one consistent format
          (value || {})["list"].each do  |crap|
            widget_id = crap["widget"]
            if (path=self.widget_map[widget_id]||self.widget_map[widget_id.to_s])
              links << {destination_object: path, title: widget_id}
            else
              raise Scrivito::ScrivitoError, "Inconsistent widget pool state detected, unable to store widgets (unable to find #{widget_id} in #{self.widget_map.inspect})"
            end
          end
        end
        self.obj.set(self.attr_name, links)
      end
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
infopark_fiona7-1.6.1.1.5 lib/fiona7/attribute_writers/widgetlist_as_linklist.rb
infopark_fiona7-1.6.1.1.1 lib/fiona7/attribute_writers/widgetlist_as_linklist.rb
infopark_fiona7-1.6.1.1.0 lib/fiona7/attribute_writers/widgetlist_as_linklist.rb
infopark_fiona7-1.2.0.2.3 lib/fiona7/attribute_writers/widgetlist_as_linklist.rb
infopark_fiona7-1.2.0.2.1 lib/fiona7/attribute_writers/widgetlist_as_linklist.rb
infopark_fiona7-1.2.0.2.2 lib/fiona7/attribute_writers/widgetlist_as_linklist.rb
infopark_fiona7-1.5.5.5.1 lib/fiona7/attribute_writers/widgetlist_as_linklist.rb
infopark_fiona7-1.5.5.5.0 lib/fiona7/attribute_writers/widgetlist_as_linklist.rb
infopark_fiona7-1.2.0.1.4 lib/fiona7/attribute_writers/widgetlist_as_linklist.rb
infopark_fiona7-1.5.5.4.1 lib/fiona7/attribute_writers/widgetlist_as_linklist.rb
infopark_fiona7-1.5.5.4.0 lib/fiona7/attribute_writers/widgetlist_as_linklist.rb
infopark_fiona7-1.2.0.1.3 lib/fiona7/attribute_writers/widgetlist_as_linklist.rb
infopark_fiona7-1.5.5.3.1 lib/fiona7/attribute_writers/widgetlist_as_linklist.rb
infopark_fiona7-1.5.4.3.0 lib/fiona7/attribute_writers/widgetlist_as_linklist.rb
infopark_fiona7-1.5.3.2.0 lib/fiona7/attribute_writers/widgetlist_as_linklist.rb
infopark_fiona7-1.5.3.2.0.pre.beta1 lib/fiona7/attribute_writers/widgetlist_as_linklist.rb
infopark_fiona7-1.5.2.1.0.pre.beta1 lib/fiona7/attribute_writers/widgetlist_as_linklist.rb
infopark_fiona7-1.5.2.0.0 lib/fiona7/attribute_writers/widgetlist_as_linklist.rb
infopark_fiona7-1.2.0.1.1 lib/fiona7/attribute_writers/widgetlist_as_linklist.rb