Module: Decidim::BreadcrumbHelper

Included in:
Accountability::StatusCell
Defined in:
decidim-core/app/helpers/decidim/breadcrumb_helper.rb

Overview

This module includes helpers to manage breadcrumb in layout

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#context_breadcrumb_itemsObject (readonly)

Returns the value of attribute context_breadcrumb_items.



6
7
8
# File 'decidim-core/app/helpers/decidim/breadcrumb_helper.rb', line 6

def context_breadcrumb_items
  @context_breadcrumb_items
end

#controller_breadcrumb_itemsObject (readonly)

Returns the value of attribute controller_breadcrumb_items.



6
7
8
# File 'decidim-core/app/helpers/decidim/breadcrumb_helper.rb', line 6

def controller_breadcrumb_items
  @controller_breadcrumb_items
end

#secondary_breadcrumb_menusObject (readonly)

Returns the value of attribute secondary_breadcrumb_menus.



6
7
8
# File 'decidim-core/app/helpers/decidim/breadcrumb_helper.rb', line 6

def secondary_breadcrumb_menus
  @secondary_breadcrumb_menus
end

Instance Method Details

#active_breadcrumb_item(target_menu) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
# File 'decidim-core/app/helpers/decidim/breadcrumb_helper.rb', line 48

def active_breadcrumb_item(target_menu)
  active_item = ::Decidim::MenuPresenter.new(target_menu, self).active_item

  return if active_item.blank?

  {
    label: active_item.label,
    url: active_item.url,
    active: active_item.active?
  }
end

Public: Returns the list of breadcrumb items to be rendered in some context.

context - The context (public or admin) to display the breadcrumb. It

determines the first element of the breadcrumb

The items are generated as the concatenation of the following 4 sections in order:

  • The root active item: This item comes from the main menu on each context and is the currently active element.

  • context_breadcrumb_items: A list which can be implemented in specific concerns and is used to display items like a participatory space or a component inside a participatory space.

  • secondary_breadcrumb_menus: A list which can be managed from HasBreadcrumbItems concern with the add_breadcrumb_item_from_menu method. The list contains the identifier of a menu to insert its items in the breadcrumb displaying the active element.

  • controller_breadcrumb_items: A list of additional breadrumb items which is expected to receive its elements from controllers and contains the last items of the breadcrumb.



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'decidim-core/app/helpers/decidim/breadcrumb_helper.rb', line 28

def breadcrumb_items(context = :public)
  @breadcrumb_items ||= [].tap do |items|
    root_active_item = if context == :admin
                         active_breadcrumb_item(:admin_menu_modules) || active_breadcrumb_item(:admin_menu)
                       else
                         active_breadcrumb_item(:menu)
                       end

    items << root_active_item if root_active_item.present?

    items.append(*context_breadcrumb_items)

    secondary_breadcrumb_menus&.each do |menu|
      active_item = active_breadcrumb_item(menu)
      items << active_item if active_item.present?
    end
    items.append(*controller_breadcrumb_items)
  end
end