Class: Decidim::System::PopulateHelp

Inherits:
Rectify::Command
  • Object
show all
Defined in:
decidim-system/app/commands/decidim/system/populate_help.rb

Overview

A command that will create default help pages for an organization.

Instance Method Summary collapse

Constructor Details

#initialize(organization) ⇒ PopulateHelp

Public: Initializes the command.

organization - An organization


10
11
12
# File 'decidim-system/app/commands/decidim/system/populate_help.rb', line 10

def initialize(organization)
  @organization = organization
end

Instance Method Details

#callObject

Executes the command.

Returns nothing.


17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'decidim-system/app/commands/decidim/system/populate_help.rb', line 17

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

#multi_translation(key, *arguments) ⇒ Object


52
53
54
# File 'decidim-system/app/commands/decidim/system/populate_help.rb', line 52

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