Sha256: 6c953519c652cc481801f2b95e8e10a4c5d82831e4fdc05cc73300082cd8b747

Contents?: true

Size: 1.13 KB

Versions: 8

Compression:

Stored size: 1.13 KB

Contents

# frozen_string_literal: true

module Decidim
  module Admin
    # A command with all the business logic when updating a static page topic.
    class UpdateStaticPageTopic < Decidim::Command
      # Public: Initializes the command.
      #
      # page - The StaticPageTopic to update
      # form - A form object with the params.
      def initialize(topic, form)
        @topic = topic
        @form = form
      end

      # Executes the command. Broadcasts these events:
      #
      # - :ok when everything is valid.
      # - :invalid if the form was not valid and we could not proceed.
      #
      # Returns nothing.
      def call
        return broadcast(:invalid) if form.invalid?

        update_topic
        broadcast(:ok)
      end

      private

      attr_reader :form

      def update_topic
        Decidim.traceability.update!(
          @topic,
          form.current_user,
          attributes
        )
      end

      def attributes
        {
          title: form.title,
          description: form.description,
          show_in_footer: form.show_in_footer,
          weight: form.weight
        }
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
decidim-admin-0.28.5 app/commands/decidim/admin/update_static_page_topic.rb
decidim-admin-0.28.4 app/commands/decidim/admin/update_static_page_topic.rb
decidim-admin-0.28.3 app/commands/decidim/admin/update_static_page_topic.rb
decidim-admin-0.28.2 app/commands/decidim/admin/update_static_page_topic.rb
decidim-admin-0.28.1 app/commands/decidim/admin/update_static_page_topic.rb
decidim-admin-0.28.0 app/commands/decidim/admin/update_static_page_topic.rb
decidim-admin-0.28.0.rc5 app/commands/decidim/admin/update_static_page_topic.rb
decidim-admin-0.28.0.rc4 app/commands/decidim/admin/update_static_page_topic.rb