Class: Decidim::System::CreateDefaultPages

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

Overview

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.

Instance Method Summary collapse

Methods inherited from Command

call, #evaluate, #method_missing, #respond_to_missing?, #transaction, #with_events

Constructor Details

#initialize(organization) ⇒ CreateDefaultPages

Public: Initializes the command.

form - A form object with the params.



12
13
14
# File 'decidim-system/app/commands/decidim/system/create_default_pages.rb', line 12

def initialize(organization)
  @organization = organization
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Decidim::Command

Instance Method Details

#callObject

Executes the command. i18n-tasks-use t(‘decidim.system.default_pages.terms-of-service’)

Returns nothing.



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'decidim-system/app/commands/decidim/system/create_default_pages.rb', line 20

def call
  Decidim::StaticPage::DEFAULT_PAGES.map do |slug|
    static_page = Decidim::StaticPage.find_or_create_by!(organization:, slug:) do |page|
      translated_slug = I18n.t(slug, scope: "decidim.system.default_pages")
      page.title = localized_attribute(translated_slug, :title)
      page.content = localized_attribute(translated_slug, :content)
      page.show_in_footer = true
      page.allow_public_access = true if slug == "terms-of-service"
    end

    create_summary_content_blocks_for(static_page) if slug == "terms-of-service"
  end
end