Sha256: d3b1f8dc9114a249afbaf06016a95a119e6965533964b047035bfb254cb0e707

Contents?: true

Size: 1.15 KB

Versions: 12

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

12 entries across 12 versions & 1 rubygems

Version Path
decidim-system-0.27.9 app/commands/decidim/system/create_default_content_blocks.rb
decidim-system-0.27.8 app/commands/decidim/system/create_default_content_blocks.rb
decidim-system-0.27.7 app/commands/decidim/system/create_default_content_blocks.rb
decidim-system-0.27.6 app/commands/decidim/system/create_default_content_blocks.rb
decidim-system-0.27.5 app/commands/decidim/system/create_default_content_blocks.rb
decidim-system-0.27.4 app/commands/decidim/system/create_default_content_blocks.rb
decidim-system-0.27.3 app/commands/decidim/system/create_default_content_blocks.rb
decidim-system-0.27.2 app/commands/decidim/system/create_default_content_blocks.rb
decidim-system-0.27.1 app/commands/decidim/system/create_default_content_blocks.rb
decidim-system-0.27.0 app/commands/decidim/system/create_default_content_blocks.rb
decidim-system-0.27.0.rc2 app/commands/decidim/system/create_default_content_blocks.rb
decidim-system-0.27.0.rc1 app/commands/decidim/system/create_default_content_blocks.rb