Sha256: 51e3a1be9465f10857aa8b8eda22eb727a1606d196481399d27ad33432dde04b

Contents?: true

Size: 951 Bytes

Versions: 60

Compression:

Stored size: 951 Bytes

Contents

# frozen_string_literal: true

module Decidim
  # Helper for rendering Decidim::Category related stuff.
  module CategoriesHelper
    def categories_for_select(scope)
      sorted_main_categories = scope.first_class.includes(:subcategories).sort_by do |category|
        translated_attribute(category.name, category.participatory_space.organization)
      end

      sorted_main_categories.flat_map do |category|
        parent = [[translated_attribute(category.name, category.participatory_space.organization), category.id]]

        sorted_subcategories = category.subcategories.sort_by do |subcategory|
          translated_attribute(subcategory.name, subcategory.participatory_space.organization)
        end

        sorted_subcategories.each do |subcategory|
          parent << ["- #{translated_attribute(subcategory.name, subcategory.participatory_space.organization)}", subcategory.id]
        end

        parent
      end
    end
  end
end

Version data entries

60 entries across 60 versions & 1 rubygems

Version Path
decidim-core-0.29.1 app/helpers/decidim/categories_helper.rb
decidim-core-0.28.4 app/helpers/decidim/categories_helper.rb
decidim-core-0.27.9 app/helpers/decidim/categories_helper.rb
decidim-core-0.29.0 app/helpers/decidim/categories_helper.rb
decidim-core-0.28.3 app/helpers/decidim/categories_helper.rb
decidim-core-0.27.8 app/helpers/decidim/categories_helper.rb
decidim-core-0.29.0.rc4 app/helpers/decidim/categories_helper.rb
decidim-core-0.29.0.rc3 app/helpers/decidim/categories_helper.rb
decidim-core-0.29.0.rc2 app/helpers/decidim/categories_helper.rb
decidim-core-0.29.0.rc1 app/helpers/decidim/categories_helper.rb
decidim-core-0.28.2 app/helpers/decidim/categories_helper.rb
decidim-core-0.27.7 app/helpers/decidim/categories_helper.rb
decidim-core-0.28.1 app/helpers/decidim/categories_helper.rb
decidim-core-0.27.6 app/helpers/decidim/categories_helper.rb
decidim-core-0.26.10 app/helpers/decidim/categories_helper.rb
decidim-core-0.26.9 app/helpers/decidim/categories_helper.rb
decidim-core-0.28.0 app/helpers/decidim/categories_helper.rb
decidim-core-0.27.5 app/helpers/decidim/categories_helper.rb
decidim-core-0.28.0.rc5 app/helpers/decidim/categories_helper.rb
decidim-core-0.28.0.rc4 app/helpers/decidim/categories_helper.rb