Class: Decidim::Admin::CreateComponent

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

Overview

This command gets called when a component is created from the admin panel.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(manifest, form, participatory_space) ⇒ CreateComponent

Public: Initializes the command.

manifest - The component’s manifest to create a component from. form - The form from which the data in this component comes from. participatory_space - The participatory space that will hold this component.



14
15
16
17
18
# File 'app/commands/decidim/admin/create_component.rb', line 14

def initialize(manifest, form, participatory_space)
  @manifest = manifest
  @form = form
  @participatory_space = participatory_space
end

Instance Attribute Details

#formObject (readonly)

Returns the value of attribute form.



7
8
9
# File 'app/commands/decidim/admin/create_component.rb', line 7

def form
  @form
end

#manifestObject (readonly)

Returns the value of attribute manifest.



7
8
9
# File 'app/commands/decidim/admin/create_component.rb', line 7

def manifest
  @manifest
end

#participatory_spaceObject (readonly)

Returns the value of attribute participatory_space.



7
8
9
# File 'app/commands/decidim/admin/create_component.rb', line 7

def participatory_space
  @participatory_space
end

Instance Method Details

#callObject

Public: Creates the Component.

Broadcasts :ok if created, :invalid otherwise.



23
24
25
26
27
28
29
30
31
32
# File 'app/commands/decidim/admin/create_component.rb', line 23

def call
  return broadcast(:invalid) if form.invalid?

  transaction do
    create_component
    run_hooks
  end

  broadcast(:ok)
end