Sha256: 1853516aafe3e2e4bc33c5faf1579536e78774ed621d10a2a6e4e6d3ba0f8eb0

Contents?: true

Size: 1.15 KB

Versions: 34

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_name: :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

34 entries across 34 versions & 1 rubygems

Version Path
decidim-system-0.26.10 app/commands/decidim/system/create_default_content_blocks.rb
decidim-system-0.26.9 app/commands/decidim/system/create_default_content_blocks.rb
decidim-system-0.26.8 app/commands/decidim/system/create_default_content_blocks.rb
decidim-system-0.26.7 app/commands/decidim/system/create_default_content_blocks.rb
decidim-system-0.26.5 app/commands/decidim/system/create_default_content_blocks.rb
decidim-system-0.26.4 app/commands/decidim/system/create_default_content_blocks.rb
decidim-system-0.26.3 app/commands/decidim/system/create_default_content_blocks.rb
decidim-system-0.26.2 app/commands/decidim/system/create_default_content_blocks.rb
decidim-system-0.26.1 app/commands/decidim/system/create_default_content_blocks.rb
decidim-system-0.26.0 app/commands/decidim/system/create_default_content_blocks.rb
decidim-system-0.26.0.rc2 app/commands/decidim/system/create_default_content_blocks.rb
decidim-system-0.26.0.rc1 app/commands/decidim/system/create_default_content_blocks.rb
decidim-system-0.25.2 app/commands/decidim/system/create_default_content_blocks.rb
decidim-system-0.25.1 app/commands/decidim/system/create_default_content_blocks.rb
decidim-system-0.25.0 app/commands/decidim/system/create_default_content_blocks.rb
decidim-system-0.25.0.rc4 app/commands/decidim/system/create_default_content_blocks.rb
decidim-system-0.25.0.rc3 app/commands/decidim/system/create_default_content_blocks.rb
decidim-system-0.25.0.rc2 app/commands/decidim/system/create_default_content_blocks.rb
decidim-system-0.25.0.rc1 app/commands/decidim/system/create_default_content_blocks.rb
decidim-system-0.24.3 app/commands/decidim/system/create_default_content_blocks.rb