Sha256: 9bfee78c365558dea08684a4d772b69c0cc548762785f4027842677b906ccb9d

Contents?: true

Size: 1.97 KB

Versions: 12

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

12 entries across 12 versions & 1 rubygems

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