Sha256: dc48e8cb790d3ab9b6266f994e514b209f743ada08e359ef51f1b7feefa661bf

Contents?: true

Size: 1.28 KB

Versions: 16

Compression:

Stored size: 1.28 KB

Contents

# frozen_string_literal: true

module Decidim
  module Admin
    # A form object to create or update pages.
    class StaticPageForm < Form
      include TranslatableAttributes

      attribute :slug, String
      translatable_attribute :title, String
      translatable_attribute :content, String
      attribute :changed_notably, Boolean
      attribute :show_in_footer, Boolean
      attribute :weight, Integer
      attribute :topic_id, Integer

      mimic :static_page

      validates :slug, presence: true
      validates :title, :content, translatable_presence: true
      validates :slug, format: { with: %r{\A[a-zA-Z]+[a-zA-Z0-9\-\_/]+\z} }, allow_blank: true

      validate :slug, :slug_uniqueness

      alias organization current_organization

      def slug
        super.to_s.downcase
      end

      def topic
        @topic ||= StaticPageTopic.find_by(
          organization: organization,
          id: topic_id
        )
      end

      def topics
        @topics ||= StaticPageTopic.where(
          organization: current_organization
        )
      end

      private

      def slug_uniqueness
        return unless organization
        return unless organization.static_pages.where(slug: slug).where.not(id: id).any?

        errors.add(:slug, :taken)
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
decidim-admin-0.23.6 app/forms/decidim/admin/static_page_form.rb
decidim-admin-0.23.5 app/forms/decidim/admin/static_page_form.rb
decidim-admin-0.23.4 app/forms/decidim/admin/static_page_form.rb
decidim-admin-0.23.3 app/forms/decidim/admin/static_page_form.rb
decidim-admin-0.23.2 app/forms/decidim/admin/static_page_form.rb
decidim-admin-0.23.1 app/forms/decidim/admin/static_page_form.rb
decidim-admin-0.23.1.rc1 app/forms/decidim/admin/static_page_form.rb
decidim-admin-0.23.0 app/forms/decidim/admin/static_page_form.rb
decidim-admin-0.22.0 app/forms/decidim/admin/static_page_form.rb
decidim-admin-0.21.0 app/forms/decidim/admin/static_page_form.rb
decidim-admin-0.20.1 app/forms/decidim/admin/static_page_form.rb
decidim-admin-0.20.0 app/forms/decidim/admin/static_page_form.rb
decidim-admin-0.19.1 app/forms/decidim/admin/static_page_form.rb
decidim-admin-0.18.1 app/forms/decidim/admin/static_page_form.rb
decidim-admin-0.19.0 app/forms/decidim/admin/static_page_form.rb
decidim-admin-0.18.0 app/forms/decidim/admin/static_page_form.rb