Skip to content

Commit

Permalink
Inline the attachment form for taxon icons
Browse files Browse the repository at this point in the history
There's no explicit support for multiple taxon attachment anywhere
else in the solidus codebase, and the attachment_partial_name was
using "paperclip" even for active_storage.
  • Loading branch information
elia committed Feb 26, 2021
1 parent 90d739b commit 9963a93
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 4 deletions.
19 changes: 18 additions & 1 deletion backend/app/views/spree/admin/taxons/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,24 @@
</div>
<% end %>

<%= render "spree/admin/taxons/attachment_forms/#{f.object.attachment_partial_name}", f: f %>
<% if Spree::Config.keep_legacy_backend_support_for_multiple_taxon_attachments %>
<%= render "spree/admin/taxons/attachment_forms/#{f.object.attachment_partial_name}", f: f %>
<% else %>
<%= f.field_container :icon do %>
<%= f.label :icon %><br>
<%= f.file_field :icon %>
<% if f.object.icon_present? %>
<%= image_tag f.object.icon(:mini) %>
<%= link_to t('spree.actions.remove'),
admin_taxonomy_taxon_attachment_path(@taxonomy,
@taxon.id,
attachment_definition: :icon,
authenticity_token: form_authenticity_token),
method: :delete,
class: 'btn btn-sm btn-danger' %>
<% end %>
<% end %>
<% end %>
</div>

<div class="col-5">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
<%
Spree::Deprecation.warn(
"This partial with its support for multiple Spree::Taxon attachments is deprecated and will be removed in a future " \
"version of Solidus, please set Spree::Config.keep_legacy_backend_support_for_multiple_taxon_attachments to false " \
"and overwrite the standard view if you need to support custom attachments."
)
%>

<% f.object.class.attachment_definitions.each do |attachment, definition| %>
<%= f.field_container attachment do %>
<%= f.label attachment %><br>
Expand Down
3 changes: 1 addition & 2 deletions core/app/models/spree/taxon/active_storage_attachment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@ module Spree::Taxon::ActiveStorageAttachment
styles: { mini: '32x32>', normal: '128x128>' },
default_style: :mini
validate :icon_is_an_image


end

def attachment_partial_name
Spree::Deprecation.warn("calling #attachment_partial_name on Spree::Taxon is deprecated without replacement.")
'paperclip'
end
end
1 change: 1 addition & 0 deletions core/app/models/spree/taxon/paperclip_attachment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def icon_present?
end

def attachment_partial_name
Spree::Deprecation.warn("calling #attachment_partial_name on Spree::Taxon is deprecated without replacement.")
'paperclip'
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ Spree.config do |config|
config.image_attachment_module = 'Spree::Image::ActiveStorageAttachment'
config.taxon_attachment_module = 'Spree::Taxon::ActiveStorageAttachment'

# Defaults
# Defaults:

# Do not try to support custom paperclip attachments of Spree::Taxon.
config.keep_legacy_backend_support_for_multiple_taxon_attachments = false

# Permission Sets:

# Uncomment and customize the following line to add custom permission sets
Expand Down
5 changes: 5 additions & 0 deletions core/lib/spree/app_configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,11 @@ class AppConfiguration < Preferences::Configuration
# @return [Integer]
preference :inventory_cache_threshold, :integer

# @!attribute [rw] keep_legacy_backend_support_for_multiple_taxon_attachments
# @return [Boolean] should we keep the legacy HTML that will show a form for each paperclip attachment
# defined on Spree::Taxon.
preference :keep_legacy_backend_support_for_multiple_taxon_attachments, :boolean, default: true

# @!attribute [rw] layout
# @return [String] template to use for layout on the frontend (default: +"spree/layouts/spree_application"+)
preference :layout, :string, default: 'spree/layouts/spree_application'
Expand Down

0 comments on commit 9963a93

Please sign in to comment.