Module: Decidim::Admin::SettingsHelper

Includes:
ScopesHelper
Defined in:
decidim-admin/app/helpers/decidim/admin/settings_helper.rb

Overview

This class contains helpers needed in order for component settings to properly render.

Constant Summary collapse

TYPES =
{
  boolean: :check_box,
  integer: :number_field,
  string: :text_field,
  float: :number_field,
  text: :text_area,
  select: :select_field,
  scope: :scope_field,
  enum: :collection_radio_buttons,
  time: :datetime_field
}.freeze

Instance Method Summary collapse

Methods included from ScopesHelper

#has_visible_scopes?, #scope_name_for_picker, #scopes_picker_field, #scopes_picker_filter, #scopes_select_field, #scopes_select_tag

Methods included from TranslatableAttributes

#default_locale?

Methods included from DecidimFormHelper

#areas_for_select, #base_error_messages, #decidim_form_for, #decidim_form_slug_url, #editor_field_tag, #form_field_has_error?, #form_required_explanation, #name_with_locale, #ordered_scopes_descendants, #ordered_scopes_descendants_for_select, #scopes_picker_field_tag, #tab_element_class_for, #translated_field_tag

Instance Method Details

#settings_attribute_input(form, attribute, name, i18n_scope, options = {}) ⇒ ActiveSupport::SafeBuffer

Renders a form field that matches a settings attribute’s type. Besides the field itself, it also renders all the metadata (like the labels and help texts)

Parameters:

  • form (Decidim::Admin::FormBuilder)

    The form in which to render the field

  • attribute (Decidim::SettingsManifest::Attribute)

    The Settings::Attribute instance with the description of the attribute.

  • name (Symbol)

    The name of the field.

  • i18n_scope (String)

    The scope where it will find all the texts for the internationalization (locales)

  • options (Hash) (defaults to: {})

    Extra options to be passed to the field helper.

Options Hash (options):

  • :tabs_prefix (String)

    The type of the setting. It can be “global-settings” or “step-N-settings”, where N is the number of the step.

  • :readonly (nil, Boolean)

    True if the input is readonly.

Returns:

  • (ActiveSupport::SafeBuffer)

    Rendered form field.



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'decidim-admin/app/helpers/decidim/admin/settings_helper.rb', line 35

def settings_attribute_input(form, attribute, name, i18n_scope, options = {})
  form_method = form_method_for_attribute(attribute, options)

  container_class = "#{name}_container"
  if options[:readonly]
    container_class += " readonly_container"
    help_text = text_for_setting(name, "readonly", i18n_scope)
  end
  help_text ||= text_for_setting(name, "help", i18n_scope)
  help_text_options = help_text ? { help_text: } : {}

  options = { label: t(name, scope: i18n_scope) }
            .merge(help_text_options)
            .merge(extra_options_for_type(form_method))
            .merge(options)

  (:div, class: container_class) do
    if attribute.translated?
      options[:tabs_id] = "#{options.delete(:tabs_prefix)}-#{name}-tabs"
      form.send(:translated, form_method, name, options)
    elsif form_method == :collection_radio_buttons
      render_enum_form_field(form, attribute, name, i18n_scope, options)
    elsif form_method == :select_field
      render_select_form_field(form, attribute, name, i18n_scope, options)
    elsif form_method == :scope_field
      scopes_select_field(form, name)
    else
      form.send(form_method, name, options)
    end
  end.html_safe
end