Module: ExtendedContentTranslation

Defined in:
lib/kete_translatable_content/extensions/extended_content_translation.rb

Overview

for ZOOM_CLASSES, extended_content is translatable_attribute however, in mongodb we store indivdual values for the extended fields and then we swap in actual translatable extended field values via individual extended field setter methods (method missing methods) the advantage is that we only have to tell mongo_translatable that extended_content is translatable at the time of system startup and we can go on declaring new extended fields dynamically

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/kete_translatable_content/extensions/extended_content_translation.rb', line 10

def self.included(base)

  #Send define method because scopes are not playing nicely together
  base.send(:define_method, :translatable_attributes) do
    return @translatable_attributes if @translatable_attributes.present?

    # klass is ::Version classes parent namespace wise
    klass = self.class

    type = klass == Topic ? topic_type : ContentType.find_by_class_name(klass.name)

    if type
      # fields = type.mapped_fields.select { |f| ['text', 'textarea', 'choice', 'autocomplete'].include?(f.ftype) }
      fields = type.mapped_fields.select { |f| ['text', 'textarea',].include?(f.ftype) }

      type_translatable_attributes = fields.collect do |f|
        unless f.multiple
          f.label_for_params.to_sym
        else
          [f.label_for_params.to_sym, Array]
        end
      end

      klass::Translation.update_keys_if_necessary_with(type_translatable_attributes)

      update_translation_for_methods_if_necessary_with(type_translatable_attributes)

      type_translatable_attribute_keys_only = type_translatable_attributes.collect do |a|
        if a.is_a?(Array)
          a[0]
        else
          a
        end
      end

      @translatable_attributes = self.class.translatable_attributes + type_translatable_attribute_keys_only
    else
      @translatable_attributes = self.class.translatable_attributes
    end
    @translatable_attributes
  end
end