Sha256: adcc107ec3eb39069b6a3f0912d65a9dc16de482d8fdff4f3ab8ce7dd5cb028f

Contents?: true

Size: 1.12 KB

Versions: 2

Compression:

Stored size: 1.12 KB

Contents

# frozen_string_literal: true

module Decidim
  module NavigationMaps
    # A form object used to configure the blueprint content block from the admin panel.
    #
    class BlueprintForm < Decidim::Form
      include TranslatableAttributes

      mimic :blueprint

      attribute :blueprint, Object
      attribute :id, Integer
      attribute :remove, Boolean
      attribute :image
      translatable_attribute :title, String
      translatable_attribute :description, String
      attribute :height, Integer

      # validate :check_image_or_blueprint
      validates :title, translatable_presence: true
      validates :height, numericality: { greater_than: 0 }

      # def check_image_or_blueprint
      #   return if image.present? || blueprint.present?

      #   errors.add(:image, "no image") unless image.present?
      #   errors.add(:blueprint, "no blueprint") unless blueprint.present?
      # end

      def ident
        id || "_"
      end

      def image?
        return unless image && image.respond_to?(:url)
        return image.content_type.start_with? "image" if image.content_type.present?
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
decidim-navigation_maps-1.1.1 app/forms/decidim/navigation_maps/blueprint_form.rb
decidim-navigation_maps-1.1.0 app/forms/decidim/navigation_maps/blueprint_form.rb