Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

[#60404] Hierarchy custom field - pdf output display only last item without hierarchy

as-opd2a2a0b06d6d
diff --git a/app/models/exports/formatters/custom_field_pdf.rb b/app/models/exports/formatters/custom_field_pdf.rb
index a299f785a16..3dba22f0796 100644
--- a/app/models/exports/formatters/custom_field_pdf.rb
+++ b/app/models/exports/formatters/custom_field_pdf.rb
@@ -18,10 +18,40 @@ module Exports
value ? I18n.t(:general_text_Yes) : I18n.t(:general_text_No)
when "text"
object.typed_custom_value_for(custom_field)
+ when "hierarchy"
+ format_hierarchy_for_export(object, custom_field)
else
object.formatted_custom_value_for(custom_field)
end
end
+
+ def format_hierarchy_for_export(object, custom_field)
+ cvs = object.custom_value_for(custom_field)
+ case cvs
+ when Array
+ cvs.map { |item| format_hierarchy_item_for_export(item) }
+ when CustomValue
+ format_hierarchy_item_for_export(cvs)
+ else
+ cvs
+ end
+ end
+
+ def format_hierarchy_item_for_export(item_value)
+ item = ::CustomField::Hierarchy::Item.find_by(id: item_value.to_s)
+ return "#{item_value} #{I18n.t(:label_not_found)}" if item.nil?
+
+ nodes = hierarchy_item_service.get_branch(item:).value!
+ nodes
+ .reject(&:root?)
+ .map do |branch_item|
+ branch_item.short.present? ? "#{branch_item.label} (#{branch_item.short})" : branch_item.label
+ end.join(" / ")
+ end
+
+ def hierarchy_item_service
+ ::CustomFields::Hierarchy::HierarchicalItemService.new
+ end
end
end
end