Sha256: 00bdd6a61e2d382f9b6a0b85267e81338f52d694e4854a76ac1a7e9dc1f48bfc

Contents?: true

Size: 1.97 KB

Versions: 46

Compression:

Stored size: 1.97 KB

Contents

# frozen_string_literal: true

module Decidim
  module System
    # A command that will create default help pages for an organization.
    class PopulateHelp < Rectify::Command
      # Public: Initializes the command.
      #
      # organization - An organization
      def initialize(organization)
        @organization = organization
      end

      # Executes the command.
      #
      # Returns nothing.
      def call
        ActiveRecord::Base.transaction do
          topic = Decidim::StaticPageTopic.create!(
            title: multi_translation("decidim.help.main_topic.title", organization: @organization.name),
            description: multi_translation("decidim.help.main_topic.description", organization: @organization.name),
            organization: @organization,
            weight: 0
          )

          Decidim::StaticPage.create!(
            slug: "help",
            title: multi_translation("decidim.help.main_topic.default_page.title", organization: @organization.name),
            content: multi_translation("decidim.help.main_topic.default_page.content", organization: @organization.name),
            topic: topic,
            organization: @organization,
            weight: 0
          )

          Decidim.participatory_space_manifests.each do |manifest|
            scope = "decidim.help.participatory_spaces.#{manifest.name}"
            next unless I18n.exists?(scope)

            Decidim::StaticPage.create!(
              title: multi_translation("#{scope}.title"),
              content: multi_translation("#{scope}.page"),
              slug: manifest.name,
              topic: topic,
              organization: @organization
            )

            ContextualHelpSection.set_content(@organization, manifest.name, multi_translation("#{scope}.contextual"))
          end
        end
      end

      def multi_translation(key, *arguments)
        Decidim::TranslationsHelper.multi_translation(key, @organization.available_locales, *arguments)
      end
    end
  end
end

Version data entries

46 entries across 46 versions & 1 rubygems

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