Sha256: 7af5d9a461dbf0d67dbe0f21bba9a277c7c4a677ac9617e8f798bc6e1741c6c9

Contents?: true

Size: 1.15 KB

Versions: 15

Compression:

Stored size: 1.15 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, :metrics, :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
        content_blocks.each_with_index do |manifest, 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

      def content_blocks
        Decidim.content_blocks.for(:homepage).select(&:default)
      end

      attr_reader :organization
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
decidim-system-0.21.0 app/commands/decidim/system/create_default_content_blocks.rb
decidim-system-0.20.1 app/commands/decidim/system/create_default_content_blocks.rb
decidim-system-0.20.0 app/commands/decidim/system/create_default_content_blocks.rb
decidim-system-0.19.1 app/commands/decidim/system/create_default_content_blocks.rb
decidim-system-0.18.1 app/commands/decidim/system/create_default_content_blocks.rb
decidim-system-0.19.0 app/commands/decidim/system/create_default_content_blocks.rb
decidim-system-0.17.2 app/commands/decidim/system/create_default_content_blocks.rb
decidim-system-0.18.0 app/commands/decidim/system/create_default_content_blocks.rb
decidim-system-0.17.1 app/commands/decidim/system/create_default_content_blocks.rb
decidim-system-0.16.1 app/commands/decidim/system/create_default_content_blocks.rb
decidim-system-0.17.0 app/commands/decidim/system/create_default_content_blocks.rb
decidim-system-0.16.0 app/commands/decidim/system/create_default_content_blocks.rb
decidim-system-0.15.2 app/commands/decidim/system/create_default_content_blocks.rb
decidim-system-0.15.1 app/commands/decidim/system/create_default_content_blocks.rb
decidim-system-0.15.0 app/commands/decidim/system/create_default_content_blocks.rb