Class: Decidim::Admin::TaxonomyItemForm

Inherits:
Form
  • Object
show all
Includes:
TranslatableAttributes
Defined in:
app/forms/decidim/admin/taxonomy_item_form.rb

Overview

A form object to be used when creating or updating a taxonomy.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.from_params(params, additional_params = {}) ⇒ Object



25
26
27
28
29
30
31
32
33
# File 'app/forms/decidim/admin/taxonomy_item_form.rb', line 25

def self.from_params(params, additional_params = {})
  additional_params[:taxonomy] = {}
  if params[:taxonomy]
    params[:taxonomy].each do |key, value|
      additional_params[:taxonomy][key[8..]] = value if key.start_with?("item_name_")
    end
  end
  super
end

Instance Method Details

#map_model(model) ⇒ Object



21
22
23
# File 'app/forms/decidim/admin/taxonomy_item_form.rb', line 21

def map_model(model)
  self.item_name = model.name
end

#parentObject



49
50
51
# File 'app/forms/decidim/admin/taxonomy_item_form.rb', line 49

def parent
  @parent ||= Decidim::Taxonomy.find_by(id: parent_id)
end

#validate_parent_id_within_same_root_taxonomyObject



35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'app/forms/decidim/admin/taxonomy_item_form.rb', line 35

def validate_parent_id_within_same_root_taxonomy
  if parent
    current_root_taxonomy = if parent.root?
                              parent
                            else
                              parent.root_taxonomy
                            end

    errors.add(:parent_id, :invalid) unless parent.root_taxonomy.id == current_root_taxonomy.id
  else
    errors.add(:parent_id, :invalid)
  end
end