Module: LcpRuby::LinkThroughHelper

Defined in:
app/helpers/lcp_ruby/link_through_helper.rb

Overview

Wrap a rendered field/column value in a link to the entry’s resolved target. No-op when the entry was not enriched with a link_chain, when the raw value is blank (so we do not render a clickable em-dash), when the chain does not resolve, when the target record is discarded, or when the user lacks :show. Every produced anchor carries data-turbo-frame=“_top” so it always performs a top-level Turbo Drive visit regardless of any enclosing frame.

Instance Method Summary collapse

Instance Method Details



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/helpers/lcp_ruby/link_through_helper.rb', line 9

def wrap_link_through(raw_value, rendered_content, record, entry)
  return rendered_content if entry.blank? || !entry.is_a?(Hash)
  return rendered_content unless entry.key?("link_chain")
  return rendered_content if raw_value.blank?

  resolved = Presenter::LinkResolver.resolve(
    record: record,
    entry: entry,
    current_user: respond_to?(:current_user) ? current_user : nil,
    evaluator_cache: (@_link_through_evaluator_cache ||= {})
  )
  return rendered_content unless resolved

  link_to(
    rendered_content,
    lcp_ruby.resource_path(lcp_slug: resolved[:slug], id: resolved[:target_record].to_param),
    data: { turbo_frame: "_top" }
  )
end