Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate elements fallbacks #1982

Merged
merged 2 commits into from
Dec 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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