Class: Locomotive::CustomFieldService
- Inherits:
-
Struct
- Object
- Struct
- Locomotive::CustomFieldService
- Defined in:
- app/services/locomotive/custom_field_service.rb
Instance Attribute Summary collapse
-
#field ⇒ Object
Returns the value of attribute field.
-
#locale ⇒ Object
Returns the value of attribute locale.
Instance Method Summary collapse
-
#update_select_options(options) ⇒ Array
Update the options of a “select” field.
Instance Attribute Details
#field ⇒ Object
Returns the value of attribute field
2 3 4 |
# File 'app/services/locomotive/custom_field_service.rb', line 2 def field @field end |
#locale ⇒ Object
Returns the value of attribute locale
2 3 4 |
# File 'app/services/locomotive/custom_field_service.rb', line 2 def locale @locale end |
Instance Method Details
#update_select_options(options) ⇒ Array
Update the options of a “select” field.
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 |
# File 'app/services/locomotive/custom_field_service.rb', line 10 def () return nil if .blank? default_locale = field._parent.site.default_locale.to_sym = false # set the right position .each_with_index do |option, position| option['position'] = position = true if option['_id'].blank? end self.field. = save_field # make sure the new options are also available in the default locale if && locale != default_locale ::Mongoid::Fields::I18n.with_locale(default_locale) do self.field.reload..each do |option| next unless option.attributes[:name][default_locale].blank? # force the name in the default locale option.name = option.attributes[:name].values.first end end save_field # we have to save it again and that's okay end self.field. end |