Module: CamaleonCms::CustomFieldsConcern

Included in:
NavMenuItemDecorator, PostDecorator, TermTaxonomyDecorator, UserDecorator, UserRoleDecorator, WidgetDecorator
Defined in:
app/decorators/camaleon_cms/custom_fields_concern.rb

Instance Method Summary collapse

Instance Method Details

#render_fieldsObject

CUSTOM FIELDS=====================================

render as html the custom fields marked for frontend



5
6
7
8
9
10
# File 'app/decorators/camaleon_cms/custom_fields_concern.rb', line 5

def render_fields
  object.cama_fetch_cache('render_fields') do
    h.controller.render_to_string(partial: 'partials/render_custom_field',
                                  locals: { fields: object.get_fields_object(true) })
  end
end

#the_field(field_key, default_val = '') ⇒ Object Also known as: the_field!

return custom field content with key field_key translated and short codes evaluated like the content default_val: default value returned when this field was not registered



15
16
17
# File 'app/decorators/camaleon_cms/custom_fields_concern.rb', line 15

def the_field(field_key, default_val = '')
  h.do_shortcode(object.get_field(field_key, default_val).to_s.translate(@_deco_locale), object)
end

#the_field_grouped(field_key, is_json_format = false, is_multiple = false) ⇒ Object

the same function as get_fields_grouped(..) but this returns translated and shortcodes evaluated



50
51
52
53
54
55
# File 'app/decorators/camaleon_cms/custom_fields_concern.rb', line 50

def the_field_grouped(field_key, is_json_format = false, is_multiple = false)
  the_fields_grouped([field_key], is_json_format).map do |v|
    is_multiple ? v.values.first : v.values.try(:first).try(:first)
  end
  # the_fields_grouped([field_key], is_json_format).map{|v| is_multiple ? v.values.first : v.values.first }
end

#the_fields(field_key) ⇒ Object

return custom field contents with key field_key translated and short codes evaluated like the content this is for multiple values



23
24
25
26
27
28
29
# File 'app/decorators/camaleon_cms/custom_fields_concern.rb', line 23

def the_fields(field_key)
  r = []
  object.get_fields(field_key).each do |text|
    r << h.do_shortcode(text.to_s.translate(@_deco_locale), object)
  end
  r
end

#the_fields_grouped(field_keys, is_json_format = false, single_value = false) ⇒ Object

the same function as get_fields_grouped(..) but this returns translated and shortcodes evaluated



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'app/decorators/camaleon_cms/custom_fields_concern.rb', line 32

def the_fields_grouped(field_keys, is_json_format = false, single_value = false)
  res = []
  object.get_fields_grouped(field_keys).each do |_group|
    group = {}.with_indifferent_access
    _group.each_key do |k|
      group[k] = if is_json_format
                   _group[k].map { |v| parse_html_json(v) }
                 else
                   _group[k].map { |v| h.do_shortcode(v.to_s.translate(@_deco_locale), object) }
                 end
      group[k] = group[k].first if single_value
    end
    res << group
  end
  res
end

#the_json_field(field_key, default_val = '') ⇒ Object Also known as: the_attribute_field

return custom field content with key field_key (only for type attributes) translated and short codes evaluated like the content default_val: default value returned when this field was not registered



72
73
74
# File 'app/decorators/camaleon_cms/custom_fields_concern.rb', line 72

def the_json_field(field_key, default_val = '')
  parse_html_json(object.get_field(field_key, default_val))
end

#the_json_fields(field_key) ⇒ Object Also known as: the_attribute_fields

return custom field contents with key field_key (only for type attributes) translated and short codes evaluated like the content this is for multiple values



60
61
62
63
64
65
66
# File 'app/decorators/camaleon_cms/custom_fields_concern.rb', line 60

def the_json_fields(field_key)
  r = []
  object.get_fields(field_key).each do |text|
    r << parse_html_json(text)
  end
  r
end