Module: Locomotive::Concerns::Site::Metafields

Extended by:
ActiveSupport::Concern
Includes:
Locomotive::Concerns::Shared::JsonAttribute
Included in:
Site
Defined in:
app/models/locomotive/concerns/site/metafields.rb

Instance Method Summary collapse

Instance Method Details

#any_localized_metafield?Boolean

Returns:


27
28
29
30
31
# File 'app/models/locomotive/concerns/site/metafields.rb', line 27

def any_localized_metafield?
  return false unless self.has_metafields?

  self.metafields_schema.any? { |g| g['fields'].any? { |f| f['localized'] ==  true } }
end

#find_metafield(name) ⇒ Object


33
34
35
36
37
38
39
40
41
42
# File 'app/models/locomotive/concerns/site/metafields.rb', line 33

def find_metafield(name)
  return nil if name.blank? || !has_metafields?

  fields = self.metafields_schema.map { |g| g['fields'] }.flatten

  fields.find do |f|
    _name = f['name'].downcase.underscore.gsub(' ', '_')
    _name == name
  end
end

#has_metafields?Boolean

Returns:


23
24
25
# File 'app/models/locomotive/concerns/site/metafields.rb', line 23

def has_metafields?
  !self.metafields_schema.blank?
end