Sha256: 2e8cc50f2be69e0b6eba7c2b7c94b1d67942e7b970da8b6b162fd8aabeba4083

Contents?: true

Size: 1.33 KB

Versions: 12

Compression:

Stored size: 1.33 KB

Contents

# frozen_string_literal: true

module Decidim
  module System
    # A command with all the business logic when creating a new organization in
    # the system. It creates the organization and invites the admin to the
    # system.
    class CreateDefaultPages < Decidim::Command
      # Public: Initializes the command.
      #
      # form - A form object with the params.
      def initialize(organization)
        @organization = organization
      end

      # Executes the command.
      #
      # Returns nothing.
      def call
        Decidim::StaticPage::DEFAULT_PAGES.map do |slug|
          Decidim::StaticPage.find_or_create_by!(organization: organization, slug: slug) do |page|
            page.title = localized_attribute(slug, :title)
            page.content = localized_attribute(slug, :content)
            page.show_in_footer = true
            page.allow_public_access = true if slug == "terms-and-conditions"
          end
        end
      end

      private

      attr_reader :organization

      def localized_attribute(slug, attribute)
        Decidim.available_locales.inject({}) do |result, locale|
          text = I18n.with_locale(locale) do
            I18n.t(attribute, scope: "decidim.system.default_pages.placeholders", page: slug)
          end

          result.update(locale => text)
        end
      end
    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_pages.rb
decidim-system-0.27.8 app/commands/decidim/system/create_default_pages.rb
decidim-system-0.27.7 app/commands/decidim/system/create_default_pages.rb
decidim-system-0.27.6 app/commands/decidim/system/create_default_pages.rb
decidim-system-0.27.5 app/commands/decidim/system/create_default_pages.rb
decidim-system-0.27.4 app/commands/decidim/system/create_default_pages.rb
decidim-system-0.27.3 app/commands/decidim/system/create_default_pages.rb
decidim-system-0.27.2 app/commands/decidim/system/create_default_pages.rb
decidim-system-0.27.1 app/commands/decidim/system/create_default_pages.rb
decidim-system-0.27.0 app/commands/decidim/system/create_default_pages.rb
decidim-system-0.27.0.rc2 app/commands/decidim/system/create_default_pages.rb
decidim-system-0.27.0.rc1 app/commands/decidim/system/create_default_pages.rb