Sha256: 2c8ca0df9df9669bd4a180fc6fe3acd8393b425add9a8bbd6120e42f78c446be
Contents?: true
Size: 1.58 KB
Versions: 13
Compression:
Stored size: 1.58 KB
Contents
module Locomotive module API module Forms class ContentTypeFieldForm < BaseForm attr_accessor :content_type_service, :existing_field attrs :_id, :name, :type, :label, :hint, :required, :localized, :unique, :position, :text_formatting, :select_options_attributes, :target, :inverse_of, :order_by, :ui_enabled, :group, :default, :class_name, :_destroy def initialize(content_type_service, existing_field, attributes) self.content_type_service = content_type_service self.existing_field = existing_field super(attributes) end 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 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 private def attach_id_to_option(name, attributes) return if existing_field.nil? if option = existing_field.select_options.where(name: name).first attributes[:_id] = option._id end end end end end end
Version data entries
13 entries across 13 versions & 1 rubygems