Class: Decidim::Admin::UpdateContentBlock

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

Overview

This command gets called when a content block is updated from the admin panel.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(form, content_block, scope) ⇒ UpdateContentBlock

Public: Initializes the command.

form - The form from which the data in this component comes from. component - The component to update. scope - the scope where the content block belongs to.



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

def initialize(form, content_block, scope)
  @form = form
  @content_block = content_block
  @scope = scope
end

Instance Attribute Details

#content_blockObject (readonly)

Returns the value of attribute content_block.



8
9
10
# File 'app/commands/decidim/admin/update_content_block.rb', line 8

def content_block
  @content_block
end

#formObject (readonly)

Returns the value of attribute form.



8
9
10
# File 'app/commands/decidim/admin/update_content_block.rb', line 8

def form
  @form
end

#scopeObject (readonly)

Returns the value of attribute scope.



8
9
10
# File 'app/commands/decidim/admin/update_content_block.rb', line 8

def scope
  @scope
end

Instance Method Details

#callObject

Public: Updates the content block settings and its attachments.

Broadcasts :ok if created, :invalid otherwise.



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

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

  transaction do
    update_content_block_settings
    update_content_block_images
    content_block.save!
  end

  broadcast(:ok)
end