Skip to content

A platform for community discussion. Free, open, simple.

1.1 KB
Raw Blame
# frozen_string_literal: true

class TagSerializer < ApplicationSerializer
  attributes :id, :name, :slug, :topic_count, :staff, :description, :description_cooked

  has_many :localizations, serializer: TagLocalizationSerializer, embed: :objects

  def slug
    object.slug_for_url
  end

  def name
    translated =
      (object.get_localization&.name if ContentLocalization.show_translated_tag?(object, scope))
    translated || object.name
  end

  def description
    translated =
      if ContentLocalization.show_translated_tag?(object, scope)
        object.get_localization&.description
      end
    translated || object.description
  end

  def description_cooked
    translated =
      if ContentLocalization.show_translated_tag?(object, scope)
        object.get_localization&.description_cooked
      end
    translated || object.description_cooked
  end

  def topic_count
    object.public_send(Tag.topic_count_column(scope))
  end

  def staff
    DiscourseTagging.staff_tag_names.include?(object.name)
  end

  def include_localizations?
    SiteSetting.content_localization_enabled && object.localizations.loaded?
  end
end