Class: Locomotive::API::Forms::ContentTypeFieldForm

Inherits:
BaseForm
  • Object
show all
Defined in:
app/api/locomotive/api/forms/content_type_field_form.rb

Instance Attribute Summary collapse

Attributes inherited from BaseForm

#_persisted, #_policy

Instance Method Summary collapse

Methods inherited from BaseForm

attributes, attrs, define_attribute, #persisted?, #serializable_hash, #set_attribute

Constructor Details

#initialize(content_type_service, existing_field, attributes) ⇒ ContentTypeFieldForm

Returns a new instance of ContentTypeFieldForm.



15
16
17
18
19
# File 'app/api/locomotive/api/forms/content_type_field_form.rb', line 15

def initialize(content_type_service, existing_field, attributes)
  self.content_type_service = content_type_service
  self.existing_field = existing_field
  super(attributes)
end

Instance Attribute Details

#content_type_serviceObject

Returns the value of attribute content_type_service.



7
8
9
# File 'app/api/locomotive/api/forms/content_type_field_form.rb', line 7

def content_type_service
  @content_type_service
end

#existing_fieldObject

Returns the value of attribute existing_field.



7
8
9
# File 'app/api/locomotive/api/forms/content_type_field_form.rb', line 7

def existing_field
  @existing_field
end

Instance Method Details

#select_options=(options) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'app/api/locomotive/api/forms/content_type_field_form.rb', line 27

def select_options=(options)
  self.select_options_attributes = options.map do |attributes|
    if (name = attributes['name']).is_a?(Hash)
      # deal with translations
      translations = attributes['name_translations'] = attributes.delete('name')
      name = translations[content_type_service.site.default_locale]
    end

    attach_id_to_option(name, attributes)

    attributes
  end
end

#target=(slug) ⇒ Object



21
22
23
24
25
# File 'app/api/locomotive/api/forms/content_type_field_form.rb', line 21

def target=(slug)
  if content_type = self.content_type_service.find_by_slug(slug).first
    self.class_name = content_type.entries_class_name
  end
end