Skip to content

Commit

Permalink
Merge pull request #1982 from tvdeyen/deprecate-elements-fallbacks
Browse files Browse the repository at this point in the history
Deprecate elements fallbacks
  • Loading branch information
tvdeyen authored Dec 22, 2020
2 parents 6d63123 + 68da3c3 commit aa02942
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 21 deletions.
18 changes: 0 additions & 18 deletions app/helpers/alchemy/elements_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,6 @@ module ElementsHelper
# <%= render_elements from_page: 'footer' %>
# </footer>
#
# === Fallback to elements from global page:
#
# You can use the fallback option as an override for elements that are stored on another page.
# So you can take elements from a global page and only if the user adds an element on current page the
# local one gets rendered.
#
# 1. You have to pass the the name of the element the fallback is for as <tt>for</tt> key.
# 2. You have to pass a <tt>page_layout</tt> name or {Alchemy::Page} from where the fallback elements is taken from as <tt>from</tt> key.
# 3. You can pass the name of element to fallback with as <tt>with</tt> key. This is optional (the element name from the <tt>for</tt> key is taken as default).
#
# <%= render_elements(fallback: {
# for: 'contact_teaser',
# from: 'sidebar',
# with: 'contact_teaser'
# }) %>
#
# === Custom elements finder:
#
# Having a custom element finder class:
Expand Down Expand Up @@ -76,8 +60,6 @@ module ElementsHelper
# The amount of elements to be rendered (begins with first element found)
# @option options [Number] :offset
# The offset to begin loading elements from
# @option options [Hash] :fallback
# Define elements that are rendered from another page.
# @option options [Boolean] :random (false)
# Randomize the output of elements
# @option options [Boolean] :reverse (false)
Expand Down
8 changes: 6 additions & 2 deletions lib/alchemy/elements_finder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ class ElementsFinder
# Randomize the output of elements
# @option options [Boolean] :reverse (false)
# Reverse the load order
# @option options [Hash] :fallback
# Define elements that are loaded from another page if no element was found on given page.
def initialize(options = {})
@options = options
end
Expand Down Expand Up @@ -83,6 +81,9 @@ def get_page(page_or_layout)
when Alchemy::Page
page_or_layout
when String
Alchemy::Deprecation.warn "Passing a String as `from_page` option to " \
"`render_elements` is deprecated and will be removed with Alchemy 6.0. " \
"Please load the page beforehand and pass it as an object instead."
Alchemy::Page.find_by(
language: Alchemy::Language.current,
page_layout: page_or_layout,
Expand All @@ -92,6 +93,9 @@ def get_page(page_or_layout)
end

def fallback_required?(elements)
if options[:fallback]
Alchemy::Deprecation.warn "Passing `fallback` options to `render_elements` is deprecated an will be removed with Alchemy 6.0."
end
options[:fallback] && elements
.where(Alchemy::Element.table_name => {name: options[:fallback][:for]})
.none?
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div id="header">
<div id="header_image">
<%= render_elements(:only => 'header', :fallback => {:for => 'header', :from => 'layout_header'}) %>
<%= render_elements(:only => 'header') %>
</div>
<%- claim = render_elements :only => ["claim"] -%>
<%- if !claim.blank? -%>
Expand Down

0 comments on commit aa02942

Please sign in to comment.