Class: GacoCms::Field

Inherits:
ApplicationRecord show all
Includes:
BuddyTranslatable
Defined in:
app/models/gaco_cms/field.rb

Constant Summary collapse

EXTRA_KINDS =
GacoCms::Config.extra_fields
KINDS =
%i[text_field text_area editor file page].concat(EXTRA_KINDS.keys)

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ApplicationRecord

#activestorage_url, #cache_key_locale, human_name

Class Method Details



47
48
49
50
51
52
53
# File 'app/models/gaco_cms/field.rb', line 47

def self.dropdown_data
  KINDS.map do |key|
    title = key.to_s.titleize
    title = ApplicationHelper.translated_value_for(EXTRA_KINDS[key][:label]) if EXTRA_KINDS[key]
    [title, key]
  end
end

Instance Method Details

#allow_translation?Boolean

Returns:

  • (Boolean)


61
62
63
64
65
66
# File 'app/models/gaco_cms/field.rb', line 61

def allow_translation?
  return false if %w[page].include?(kind)

  res = EXTRA_KINDS.dig(kind&.to_sym, :translatable)
  res.nil? ? true : res
end

#default_value_tplObject



55
56
57
58
59
# File 'app/models/gaco_cms/field.rb', line 55

def default_value_tpl
  return "/gaco_cms/admin/field_groups_renderer/default_value/#{kind}" if kind == 'page'

  EXTRA_KINDS.dig(kind&.to_sym, :default_value_tpl)
end

#tplObject



68
69
70
# File 'app/models/gaco_cms/field.rb', line 68

def tpl
  EXTRA_KINDS.dig(kind&.to_sym, :tpl) || "/gaco_cms/admin/field_groups_renderer/fields/#{kind}"
end