knowledge_base_helper.rb 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. module KnowledgeBaseHelper
  2. def effective_layout_name(knowledge_base, object)
  3. layout_prefix = object.present? ? :category : :homepage
  4. knowledge_base.send("#{layout_prefix}_layout")
  5. end
  6. def custom_path_if_needed(path, knowledge_base, full: false)
  7. return path if !knowledge_base.custom_address_matches?(request)
  8. custom_address = knowledge_base.custom_address_uri
  9. return path if !custom_address
  10. custom_path = knowledge_base.custom_address_path(path)
  11. prefix = full ? knowledge_base.custom_address_prefix(request) : ''
  12. "#{prefix}#{custom_path}"
  13. end
  14. def translation_locale_code(translation)
  15. translation.kb_locale.system_locale.locale
  16. end
  17. def edit_kb_link_label(object)
  18. suffix = case object
  19. when KnowledgeBase::Answer
  20. 'answer'
  21. when KnowledgeBase::Category
  22. 'category'
  23. when KnowledgeBase
  24. 'knowledge base'
  25. end
  26. "edit #{suffix}"
  27. end
  28. def build_kb_link(object)
  29. locale = params.fetch(:locale, object.translation.kb_locale)
  30. path = case object
  31. when KnowledgeBase::Answer
  32. "knowledge_base/#{object.category.knowledge_base.id}/locale/#{locale}/answer/#{object.id}/edit"
  33. when KnowledgeBase::Category
  34. "knowledge_base/#{object.knowledge_base.id}/locale/#{locale}/category/#{object.id}/edit"
  35. when KnowledgeBase
  36. "knowledge_base/#{object.id}/locale/#{locale}/edit"
  37. end
  38. build_zammad_link path
  39. end
  40. def build_zammad_link(path)
  41. host, port = Setting.get('fqdn').split ':'
  42. scheme = Setting.get('http_type')
  43. URI::Generic
  44. .build(host: host, scheme: scheme, port: port, fragment: path)
  45. .to_s
  46. end
  47. def dropdown_menu_direction
  48. system_locale_via_uri.dir == 'ltr' ? 'right' : 'left'
  49. end
  50. def canonical_link_tag(knowledge_base, *objects)
  51. path = kb_public_system_path(*objects)
  52. tag :link, rel: 'canonical', href: knowledge_base.canonical_url(path)
  53. end
  54. def kb_public_system_path(*objects)
  55. objects
  56. .compact
  57. .map { |elem| elem.translation.to_param }
  58. .unshift(help_root_path)
  59. .join('/')
  60. end
  61. end