Class: Decidim::Templates::Admin::CreateTemplate

Inherits:
Command
  • Object
show all
Defined in:
app/commands/decidim/templates/admin/create_template.rb

Instance Method Summary collapse

Constructor Details

#initialize(form) ⇒ CreateTemplate

Initializes the command.

form - The source for this generic Template.



10
11
12
# File 'app/commands/decidim/templates/admin/create_template.rb', line 10

def initialize(form)
  @form = form
end

Instance Method Details

#callObject

Executes the command. Broadcasts these events:

  • :ok when everything is valid.

  • :invalid if the form was not valid and we could not proceed.

Returns nothing.



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/commands/decidim/templates/admin/create_template.rb', line 20

def call
  return broadcast(:invalid) unless @form.valid?

  @template = Decidim.traceability.create!(
    Template,
    @form.current_user,
    name: @form.name,
    description: @form.description,
    organization: @form.current_organization,
    field_values:,
    target:
  )

  assign_template!

  broadcast(:ok, @template)
end