Module: Locomotive::ContentEntriesHelper

Defined in:
app/helpers/locomotive/content_entries_helper.rb

Instance Method Summary collapse

Instance Method Details

#can_edit_public_submission_accounts?(content_type) ⇒ Boolean

Returns:



73
74
75
# File 'app/helpers/locomotive/content_entries_helper.rb', line 73

def can_edit_public_submission_accounts?(content_type)
  policy(content_type).update? && content_type.public_submission_enabled?
end

#content_entries_paths_by_slug(site) ⇒ Object

Paths to the list of content entries grouped by content type slug



67
68
69
70
71
# File 'app/helpers/locomotive/content_entries_helper.rb', line 67

def content_entries_paths_by_slug(site)
  site.content_types.pluck(:slug).map do |slug|
    [slug, content_entries_path(site, slug)]
  end.to_h
end

#display_content_entry_tab?(content_type, name) ⇒ Boolean

Tell if the tab specified by the name argument should be displayed or not. It is based on the display_settings property of the content type.

Returns:



7
8
9
10
11
# File 'app/helpers/locomotive/content_entries_helper.rb', line 7

def display_content_entry_tab?(content_type, name)
  return true if content_type.display_settings.blank?

  content_type.display_settings[name.to_s] != false
end

#each_content_entry_group(content_type, &block) ⇒ Array

List the labels and url of “groups” used to group the entries of a content type. 2 sources:

  • from a select field

  • from a belongs_to field

Parameters:

  • content_type (Object)

    The content type

Returns:

  • (Array)

    The list of labels and urls (Hash)



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'app/helpers/locomotive/content_entries_helper.rb', line 44

def each_content_entry_group(content_type, &block)
  field       = content_type.group_by_field
  groups      = content_type.list_of_groups || []

  groups.each do |group|
    where = if field.type == 'boolean'
      %({"#{field.name}": #{group[:_id]}})
    else
      %({"#{field.name}_id": "#{group[:_id]}"})
    end

    block.call({
      name: group[:name],
      url:  content_entries_path(current_site, content_type.slug, {
        group:  group[:name],
        where:  where,
        q:      params[:q]
      })
    })
  end
end

#label_for_custom_field(entry, field) ⇒ String

Display the label related to a field of a content entry. If the field is not localized, we just display the label. If the field is localized, then we display a nice flag icon to let the end-user know about it.

Parameters:

  • entry (Object)

    The content entry

  • field (Object)

    The custom field

Returns:

  • (String)

    The label with or without the icon



23
24
25
26
27
28
29
30
31
32
33
# File 'app/helpers/locomotive/content_entries_helper.rb', line 23

def label_for_custom_field(entry, field)
  if field.localized?
    translated_css = entry.translated_field?(field) ? '' : 'untranslated'

    icon = (:i, '', class: "fa fa-globe #{translated_css}")

    "#{icon} #{field.label}".html_safe
  else
    field.label
  end
end