Class: Decidim::Feeds::Admin::CreateFeed

Inherits:
Command
  • Object
show all
Includes:
MultipleAttachmentsMethods
Defined in:
app/commands/decidim/feeds/admin/create_feed.rb

Overview

A command with all the business logic when creating a new participatory feed in the system.

Instance Method Summary collapse

Constructor Details

#initialize(form) ⇒ CreateFeed

Public: Initializes the command.

form - A form object with the params.



14
15
16
# File 'app/commands/decidim/feeds/admin/create_feed.rb', line 14

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.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'app/commands/decidim/feeds/admin/create_feed.rb', line 24

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

  if process_attachments?
    build_attachments
    return broadcast(:invalid) if attachments_invalid?
  end

  if feed.persisted?
    # link_participatory_processes(feed)
    # Decidim::ContentBlocksCreator.new(feed).create_default!

    broadcast(:ok, feed)
  else
    # form.errors.add(:hero_image, feed.errors[:hero_image]) if feed.errors.include? :hero_image
    # form.errors.add(:banner_image, feed.errors[:banner_image]) if feed.errors.include? :banner_image
    broadcast(:invalid)
  end
end