Sha256: 371001d9a41dab2dab3c8701cec59330d2b92fc114134fbe05b49661b50ae4c3

Contents?: true

Size: 1.3 KB

Versions: 12

Compression:

Stored size: 1.3 KB

Contents

# frozen_string_literal: true

module Decidim
  class ContextualHelpSection < ApplicationRecord
    include Decidim::TranslatableResource
    include Decidim::Traceable

    translatable_fields :content

    belongs_to :organization, class_name: "Decidim::Organization"
    validates :content, presence: true

    def self.log_presenter_class_for(_log)
      Decidim::AdminLog::ContextualHelpSectionPresenter
    end

    # Public: Finds content given an id
    #
    # organization - The Organization to scope the content to
    # id - A String with the id
    #
    # Returns a Hash with the localized content
    def self.find_content(organization, id)
      find_by(organization: organization, section_id: id).try(:content) || {}
    end

    # Public: Stores the content.
    #
    # organization - The Organization to scope the content to
    # id           - A String with the id
    # content      - A Hash with the content to store
    #
    # Returns a Hash with the localized content
    def self.set_content(organization, id, content)
      item = find_or_initialize_by(
        organization: organization,
        section_id: id
      )

      if content.present? && content.values.any?(&:present?)
        item.update!(content: content)
      else
        item.destroy!
      end

      content
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
decidim-core-0.27.9 app/models/decidim/contextual_help_section.rb
decidim-core-0.27.8 app/models/decidim/contextual_help_section.rb
decidim-core-0.27.7 app/models/decidim/contextual_help_section.rb
decidim-core-0.27.6 app/models/decidim/contextual_help_section.rb
decidim-core-0.27.5 app/models/decidim/contextual_help_section.rb
decidim-core-0.27.4 app/models/decidim/contextual_help_section.rb
decidim-core-0.27.3 app/models/decidim/contextual_help_section.rb
decidim-core-0.27.2 app/models/decidim/contextual_help_section.rb
decidim-core-0.27.1 app/models/decidim/contextual_help_section.rb
decidim-core-0.27.0 app/models/decidim/contextual_help_section.rb
decidim-core-0.27.0.rc2 app/models/decidim/contextual_help_section.rb
decidim-core-0.27.0.rc1 app/models/decidim/contextual_help_section.rb