Sha256: 9f0e256dceb8e82cc3c03dc9b01778266826e3708795dcdfb0457b4c1610a289

Contents?: true

Size: 1.27 KB

Versions: 19

Compression:

Stored size: 1.27 KB

Contents

# frozen_string_literal: true

module Decidim
  module Admin
    # This command gets called when a component is created from the admin panel.
    class CreateComponent < Decidim::Command
      attr_reader :form, :manifest, :participatory_space

      # Public: Initializes the command.
      #
      # form - The form from which the data in this component comes from.
      def initialize(form)
        @form = form
        @manifest = form.manifest
      end

      # Public: Creates the Component.
      #
      # Broadcasts :ok if created, :invalid otherwise.
      def call
        return broadcast(:invalid) if form.invalid?

        transaction do
          create_component
          run_hooks
        end

        broadcast(:ok)
      end

      private

      def create_component
        @component = Decidim.traceability.create!(
          Component,
          form.current_user,
          manifest_name: manifest.name,
          name: form.name,
          participatory_space: form.participatory_space,
          weight: form.weight,
          settings: form.settings,
          default_step_settings: form.default_step_settings,
          step_settings: form.step_settings
        )
      end

      def run_hooks
        manifest.run_hooks(:create, @component)
      end
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
decidim-admin-0.28.4 app/commands/decidim/admin/create_component.rb
decidim-admin-0.27.9 app/commands/decidim/admin/create_component.rb
decidim-admin-0.28.3 app/commands/decidim/admin/create_component.rb
decidim-admin-0.27.8 app/commands/decidim/admin/create_component.rb
decidim-admin-0.28.2 app/commands/decidim/admin/create_component.rb
decidim-admin-0.27.7 app/commands/decidim/admin/create_component.rb
decidim-admin-0.28.1 app/commands/decidim/admin/create_component.rb
decidim-admin-0.27.6 app/commands/decidim/admin/create_component.rb
decidim-admin-0.28.0 app/commands/decidim/admin/create_component.rb
decidim-admin-0.27.5 app/commands/decidim/admin/create_component.rb
decidim-admin-0.28.0.rc5 app/commands/decidim/admin/create_component.rb
decidim-admin-0.28.0.rc4 app/commands/decidim/admin/create_component.rb
decidim-admin-0.27.4 app/commands/decidim/admin/create_component.rb
decidim-admin-0.27.3 app/commands/decidim/admin/create_component.rb
decidim-admin-0.27.2 app/commands/decidim/admin/create_component.rb
decidim-admin-0.27.1 app/commands/decidim/admin/create_component.rb
decidim-admin-0.27.0 app/commands/decidim/admin/create_component.rb
decidim-admin-0.27.0.rc2 app/commands/decidim/admin/create_component.rb
decidim-admin-0.27.0.rc1 app/commands/decidim/admin/create_component.rb