Class: Scrivito::PageConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/fiona7/scrivito_patches/page_config.rb

Instance Method Summary collapse

Instance Method Details

#current_page_configObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/fiona7/scrivito_patches/page_config.rb', line 5

def current_page_config
  # TODO: add permission info
  return {} unless obj
  config = {
    id: obj.id,
    path: obj.path,
    obj_class: obj.obj_class,
    description_for_editor: obj.description_for_editor,
    has_children: obj.children.reject(&:binary?).any?,
    has_conflict: obj.has_conflict?,
    has_details_view: obj_has_details_view?,
    modification: modification(obj),
    parent_path: obj.parent_path,
    restriction_messages: editor.restriction_messages_for(obj),
  }
  if ::Fiona7.workflows_enabled?
    fiona_obj = obj.fiona_obj
    if fiona_obj.workflow.present?
      # without a workflow or with workflows disabled this will be falsy
      config[:workflow]         = true
      # this just the returns the currently set editor
      config[:editor]           = fiona_obj.editor
      # this is the most important bit: when to disable the editing
      # altough simple this implementation handles the following cases:
      # 1. someone outside the workflow visits the page
      # 2. a current editor within the workflow visits the page
      # 3. someone within the workflow visits the page
      config[:editing_disabled] = fiona_obj.editor != editor.id
      # this contains validActionKeys from cms
      # TODO: this should be implemented in reactor
      config[:buttons]          = fiona_obj.send(:crul_obj).valid_actions
    end
  end

  config
end