Module: Hyrax::WorkFormHelper

Included in:
HyraxHelperBehavior
Defined in:
app/helpers/hyrax/work_form_helper.rb

Instance Method Summary collapse

Instance Method Details

#admin_set_optionsArray<Array<String, String, Hash>] options for the admin set drop down.

TODO:

this implementation hits database backends (solr) and is invoked from views. refactor to avoid

Returns Array<Array<String, String, Hash>] options for the admin set drop down.

Returns:

  • (Array<Array<String, String, Hash>] options for the admin set drop down.)

    Array<Array<String, String, Hash>] options for the admin set drop down.



8
9
10
11
12
13
# File 'app/helpers/hyrax/work_form_helper.rb', line 8

def admin_set_options
  return @admin_set_options.select_options if @admin_set_options

  service = Hyrax::AdminSetService.new(controller)
  Hyrax::AdminSetOptionsPresenter.new(service).select_options
end

#form_file_set_select_for(parent:) ⇒ Array<Hash{String => String}>

Constructs a hash for a form ‘select`.

Parameters:

  • form (Object)

Returns:

  • (Array<Hash{String => String}>)

    a map from file set labels to ids for the parent object



89
90
91
92
93
94
95
96
97
98
99
# File 'app/helpers/hyrax/work_form_helper.rb', line 89

def form_file_set_select_for(parent:)
  return parent.select_files if parent.respond_to?(:select_files)
  return {} unless parent.respond_to?(:member_ids)

  file_sets =
    Hyrax::PcdmMemberPresenterFactory.new(parent, nil).file_set_presenters

  file_sets.each_with_object({}) do |presenter, hash|
    hash[presenter.title_or_label] = presenter.id
  end
end

#form_progress_sections_forArray<String>

This helper allows downstream applications and engines to add additional sections to be rendered after the visibility section in the Save Work panel on the work form.

Examples:

with additional sections

Override this helper and ensure that it loads after Hyrax's helpers.
module WorksHelper
  def form_progress_sections_for(*)
    super + ["my_new_section"]
  end
end
Add the new section partial at app/views/hyrax/base/_form_progress_my_new_section.html.erb

Parameters:

Returns:

  • (Array<String>)

    the list of names of sections to be rendered in the form_progress panel



78
79
80
# File 'app/helpers/hyrax/work_form_helper.rb', line 78

def form_progress_sections_for(*)
  []
end

#form_tab_label_for(form:, tab:) ⇒ String

This helper allows downstream applications and engines to change the label of tabs to be rendered on the work form.

Examples:

passing information from the form into the translations

Override this helper and ensure that it loads after Hyrax's helpers.
module WorksHelper
  def form_tab_label_for(form:, tab:)
    if tab == 'metadata'
      t("hyrax.works.form.tab.#{tab}", title: form.model.title.first)
    else
      super
    end
  end
end

Parameters:

Returns:

  • (String)

    the label of the tab to be rendered in the form



59
60
61
# File 'app/helpers/hyrax/work_form_helper.rb', line 59

def form_tab_label_for(form:, tab:) # rubocop:disable Lint/UnusedMethodArgument
  t("hyrax.works.form.tab.#{tab}")
end

#form_tabs_for(form:) ⇒ Array<String>

TODO:

The share tab isn’t included because it wasn’t in guts4form. guts4form should be cleaned up so share is treated the same as other tabs and can be included below.

This helper allows downstream applications and engines to add/remove/reorder the tabs to be rendered on the work form.

Examples:

with additional tabs

Override this helper and ensure that it loads after Hyrax's helpers.
module WorksHelper
  def form_tabs_for(form:)
    super + ["my_new_tab"]
  end
end
Add the new section partial at app/views/hyrax/base/_form_my_new_tab.html.erb

Parameters:

Returns:

  • (Array<String>)

    the list of names of tabs to be rendered in the form



32
33
34
35
36
37
38
# File 'app/helpers/hyrax/work_form_helper.rb', line 32

def form_tabs_for(form:)
  if form.instance_of? Hyrax::Forms::BatchUploadForm
    %w[files metadata relationships]
  else
    %w[metadata files relationships]
  end
end