Skip to content

Commit

Permalink
Plugin manager register field_name_attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
thiagoyoussef committed Nov 18, 2024
1 parent 4e34a5a commit a561545
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 6 additions & 0 deletions lib/avo/plugin_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ def register(name, priority: 10)
end

def register_field(method_name, klass)
# Avo.boot method is executed multiple times.
# During the first run, it correctly loads descendants of Avo::Fields::Base.
# Plugins are then loaded, introducing additional descendants to Avo::Fields::Base.
# On subsequent runs, Avo::Fields::Base descendants now include these plugin fields.
# This field_name_attribute assign forces the field name to retain the registered name instead of being computed dynamically from the field class.
klass.field_name_attribute = method_name
Avo.field_manager.load_field method_name, klass
end

Expand Down
2 changes: 0 additions & 2 deletions pluggy/lib/pluggy/fields/radio_field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ class RadioField < Avo::Fields::BaseField

attr_reader :options

self.field_name_attribute = :pluggy_radio

def initialize(id, **args, &block)
super(id, **args, &block)

Expand Down

0 comments on commit a561545

Please sign in to comment.