Class: Decidim::Toggle::UpdateLocaleForm
- Inherits:
-
Form
- Object
- Form
- Decidim::Toggle::UpdateLocaleForm
- Defined in:
- app/forms/decidim/toggle/update_locale_form.rb
Class Method Summary collapse
- .collection_for_available_locales ⇒ Object
- .collection_for_default_locale ⇒ Object
- .collection_for_machine_translation_display_priority ⇒ Object
- .from_model(organization) ⇒ Object
- .from_params(params, additional_params = {}) ⇒ Object
Instance Method Summary collapse
-
#available_locales ⇒ Object
Decidim::Form delegates :available_locales to current_organization; this form is often built without context (e.g. system settings tabs), so prefer the attribute value.
- #clean_available_locales ⇒ Object
Class Method Details
.collection_for_available_locales ⇒ Object
63 64 65 |
# File 'app/forms/decidim/toggle/update_locale_form.rb', line 63 def self.collection_for_available_locales I18n.available_locales.map { |l| [l.to_s, l.to_s] } end |
.collection_for_default_locale ⇒ Object
67 68 69 |
# File 'app/forms/decidim/toggle/update_locale_form.rb', line 67 def self.collection_for_default_locale I18n.available_locales.map { |l| [l.to_s, l.to_s] } end |
.collection_for_machine_translation_display_priority ⇒ Object
52 53 54 55 56 57 58 59 60 61 |
# File 'app/forms/decidim/toggle/update_locale_form.rb', line 52 def self.collection_for_machine_translation_display_priority return [] unless defined?(Decidim::Organization::AVAILABLE_MACHINE_TRANSLATION_DISPLAY_PRIORITIES) Decidim::Organization::AVAILABLE_MACHINE_TRANSLATION_DISPLAY_PRIORITIES.map do |priority| [ priority, I18n.t("activemodel.attributes.organization.machine_translation_display_priority_#{priority}", default: priority) ] end end |
.from_model(organization) ⇒ Object
28 29 30 31 32 33 |
# File 'app/forms/decidim/toggle/update_locale_form.rb', line 28 def self.from_model(organization) attrs = locale_attrs_from(organization) attrs[:enable_machine_translations] = organization.enable_machine_translations if organization.respond_to?(:enable_machine_translations) attrs[:machine_translation_display_priority] = organization.machine_translation_display_priority if organization.respond_to?(:machine_translation_display_priority) from_params(attrs) end |
.from_params(params, additional_params = {}) ⇒ Object
71 72 73 74 75 76 77 78 79 |
# File 'app/forms/decidim/toggle/update_locale_form.rb', line 71 def self.from_params(params, additional_params = {}) params = params.to_h.with_indifferent_access if params.respond_to?(:to_h) attrs = params[:organization] || params if attrs[:available_locales].is_a?(Hash) params = params.dup params[:organization] = (params[:organization] || {}).merge(available_locales: attrs[:available_locales].keys.compact_blank) end super(params, additional_params) end |
Instance Method Details
#available_locales ⇒ Object
Decidim::Form delegates :available_locales to current_organization; this form is often built without context (e.g. system settings tabs), so prefer the attribute value.
15 16 17 |
# File 'app/forms/decidim/toggle/update_locale_form.rb', line 15 def available_locales attributes["available_locales"] end |
#clean_available_locales ⇒ Object
81 82 83 84 85 86 |
# File 'app/forms/decidim/toggle/update_locale_form.rb', line 81 def clean_available_locales return [] if available_locales.blank? allowed = i18n_available_locales_set Array(available_locales).map(&:to_s).select { |l| allowed.include?(l) } end |