Sha256: 780fc903ace7f19cdb08e133dde0cdeeafc6a668281a5c3c6dcfe6bfd2c8dc6b

Contents?: true

Size: 1.05 KB

Versions: 4

Compression:

Stored size: 1.05 KB

Contents

# frozen_string_literal: true

module Decidim
  module System
    # A command with all the business logic to create the default content blocks
    # for a newly-created organization.
    class CreateDefaultContentBlocks < Rectify::Command
      DEFAULT_CONTENT_BLOCKS =
        [:hero, :sub_hero, :highlighted_content_banner, :how_to_participate, :stats, :footer_sub_hero].freeze

      # Public: Initializes the command.
      #
      # form - A form object with the params.
      def initialize(organization)
        @organization = organization
      end

      # Executes the command.
      #
      # Returns nothing.
      def call
        DEFAULT_CONTENT_BLOCKS.each_with_index do |manifest_name, index|
          weight = (index + 1) * 10
          Decidim::ContentBlock.create(
            decidim_organization_id: organization.id,
            weight: weight,
            scope: :homepage,
            manifest_name: manifest_name,
            published_at: Time.current
          )
        end
      end

      private

      attr_reader :organization
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
decidim-system-0.14.4 app/commands/decidim/system/create_default_content_blocks.rb
decidim-system-0.14.3 app/commands/decidim/system/create_default_content_blocks.rb
decidim-system-0.14.2 app/commands/decidim/system/create_default_content_blocks.rb
decidim-system-0.14.1 app/commands/decidim/system/create_default_content_blocks.rb