app/helpers/blacklight/component_helper_behavior.rb in blacklight-7.11.1 vs app/helpers/blacklight/component_helper_behavior.rb in blacklight-7.12.0
- old
+ new
@@ -1,21 +1,27 @@
# frozen_string_literal: true
module Blacklight
module ComponentHelperBehavior
+ extend Deprecation
+
+ # @deprecated
def document_action_label action, opts
t("blacklight.tools.#{action}", default: opts.label || action.to_s.humanize)
end
+ deprecation_deprecate :document_action_label
+ # @deprecated
def document_action_path action_opts, url_opts = nil
if action_opts.path
send(action_opts.path, url_opts)
elsif url_opts[:id].class.respond_to?(:model_name)
url_for([action_opts.key, url_opts[:id]])
else
send("#{action_opts.key}_#{controller_name}_path", url_opts)
end
end
+ deprecation_deprecate :document_action_path
##
# Render "document actions" area for navigation header
# (normally renders "Saved Searches", "History", "Bookmarks")
# These things are added by add_nav_action and the default config is
@@ -34,26 +40,28 @@
# @param [SolrDocument] document
# @param [Hash] options
# @option options [String] :wrapping_class
# @return [String]
def render_index_doc_actions(document, options = {})
+ actions = filter_partials(blacklight_config.view_config(document_index_view_type).document_actions, { document: document }.merge(options)).map { |_k, v| v }
wrapping_class = options.delete(:wrapping_class) || "index-document-functions"
- rendered = render_filtered_partials(blacklight_config.view_config(document_index_view_type).document_actions, { document: document }.merge(options))
- tag.div(rendered, class: wrapping_class) if rendered.present?
+
+ render(Blacklight::Document::ActionsComponent.new(document: document, actions: actions, options: options, classes: wrapping_class))
end
##
# Render "collection actions" area for search results view
# (normally renders next to pagination at the top of the result set)
#
# @param [Hash] options
# @option options [String] :wrapping_class
# @return [String]
def render_results_collection_tools(options = {})
+ actions = filter_partials(blacklight_config.view_config(document_index_view_type).collection_actions, options).map { |_k, v| v }
wrapping_class = options.delete(:wrapping_class) || "search-widgets"
- rendered = render_filtered_partials(blacklight_config.view_config(document_index_view_type).collection_actions, options)
- tag.div(rendered, class: wrapping_class) if rendered.present?
+
+ render(Blacklight::Document::ActionsComponent.new(actions: actions, options: options, classes: wrapping_class))
end
##
# Render "document actions" for the item detail 'show' view.
# (this normally renders next to title)
@@ -61,15 +69,37 @@
# By default includes 'Bookmarks'
#
# @param [SolrDocument] document
# @param [Hash] options
# @return [String]
- def render_show_doc_actions(document = @document, options = {}, &block)
- render_filtered_partials(blacklight_config.show.document_actions, { document: document }.merge(options), &block)
+ def render_show_doc_actions(document = @document, url_opts: {}, **options)
+ document = options[:document] if options.key? :document
+
+ actions = document_actions(document, options: options)
+
+ if block_given?
+ # TODO: Deprecate this behavior and replace it with a separate component?
+ # Deprecation.warn(Blacklight::ComponentHelperBehavior, 'Pass a block to #render_show_doc_actions is deprecated')
+ actions.each do |action|
+ yield action, render((action.component || Blacklight::Document::ActionComponent).new(action: action, document: document, options: options, url_opts: url_opts))
+ end
+
+ nil
+ else
+ render(Blacklight::Document::ActionsComponent.new(document: document, actions: actions, options: options, url_opts: url_opts))
+ end
end
+ def render_show_doc_actions_method_from_blacklight?
+ method(:render_show_doc_actions).owner == Blacklight::ComponentHelperBehavior
+ end
+
def show_doc_actions?(document = @document, options = {})
filter_partials(blacklight_config.show.document_actions, { document: document }.merge(options)).any?
+ end
+
+ def document_actions(document, options: {})
+ filter_partials(blacklight_config.show.document_actions, { document: document }.merge(options)).map { |_k, v| v }
end
private
def render_filtered_partials(partials, options = {})