Inherit from builder instead of monkey patching it
We were monkey-patching FoundationRailsHelper::Formbuilder, which made form customization difficult. We can inherit from it, which is the standard way of extending what an existing class does, and make our form the default one.
This commit is contained in:
@@ -6,6 +6,7 @@ class ApplicationController < ActionController::Base
|
||||
include HasOrders
|
||||
include AccessDeniedHandler
|
||||
|
||||
default_form_builder ConsulFormBuilder
|
||||
protect_from_forgery with: :exception
|
||||
|
||||
before_action :authenticate_http_basic, if: :http_basic_auth_site?
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
class Management::BaseController < ActionController::Base
|
||||
include GlobalizeFallbacks
|
||||
layout "management"
|
||||
default_form_builder ConsulFormBuilder
|
||||
|
||||
before_action :verify_manager
|
||||
before_action :set_locale
|
||||
|
||||
@@ -3,6 +3,7 @@ require "manager_authenticator"
|
||||
class Management::SessionsController < ActionController::Base
|
||||
include GlobalizeFallbacks
|
||||
include AccessDeniedHandler
|
||||
default_form_builder ConsulFormBuilder
|
||||
|
||||
def create
|
||||
destroy_session
|
||||
|
||||
@@ -18,7 +18,7 @@ module TranslatableFormHelper
|
||||
"highlight" if translations_interface_enabled?
|
||||
end
|
||||
|
||||
class TranslatableFormBuilder < FoundationRailsHelper::FormBuilder
|
||||
class TranslatableFormBuilder < ConsulFormBuilder
|
||||
attr_accessor :translations
|
||||
|
||||
def translatable_fields(&block)
|
||||
@@ -94,7 +94,7 @@ module TranslatableFormHelper
|
||||
end
|
||||
end
|
||||
|
||||
class TranslationsFieldsBuilder < FoundationRailsHelper::FormBuilder
|
||||
class TranslationsFieldsBuilder < ConsulFormBuilder
|
||||
%i[text_field text_area cktext_area].each do |field|
|
||||
define_method field do |attribute, options = {}|
|
||||
custom_label(attribute, options[:label], options[:label_options]) +
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
module FoundationRailsHelper
|
||||
class FormBuilder < ActionView::Helpers::FormBuilder
|
||||
def cktext_area(attribute, options)
|
||||
field(attribute, options) do |opts|
|
||||
super(attribute, opts)
|
||||
end
|
||||
end
|
||||
|
||||
def enum_select(attribute, options = {}, html_options = {})
|
||||
choices = object.class.send(attribute.to_s.pluralize).keys.map do |name|
|
||||
[object.class.human_attribute_name("#{attribute}.#{name}"), name]
|
||||
end
|
||||
|
||||
select attribute, choices, options, html_options
|
||||
end
|
||||
end
|
||||
end
|
||||
15
lib/consul_form_builder.rb
Normal file
15
lib/consul_form_builder.rb
Normal file
@@ -0,0 +1,15 @@
|
||||
class ConsulFormBuilder < FoundationRailsHelper::FormBuilder
|
||||
def cktext_area(attribute, options)
|
||||
field(attribute, options) do |opts|
|
||||
super(attribute, opts)
|
||||
end
|
||||
end
|
||||
|
||||
def enum_select(attribute, options = {}, html_options = {})
|
||||
choices = object.class.send(attribute.to_s.pluralize).keys.map do |name|
|
||||
[object.class.human_attribute_name("#{attribute}.#{name}"), name]
|
||||
end
|
||||
|
||||
select attribute, choices, options, html_options
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user