DEV: Allow setting max_length for field types using the plugin API (#24635)

This commit is contained in:
Daniel Waterworth 2023-11-29 14:17:12 -06:00
parent 473b7d9a4f
commit 7f3edcbdc6
2 changed files with 23 additions and 11 deletions

View File

@ -114,7 +114,9 @@ module HasCustomFields
get_custom_field_descriptor(key).append_field(target, key, value)
end
def register_custom_field_type(name, type, max_length: DEFAULT_FIELD_DESCRIPTOR.max_length)
def register_custom_field_type(name, type, max_length: nil)
max_length ||= DEFAULT_FIELD_DESCRIPTOR.max_length
if Array === type
Discourse.deprecate(
"Array types for custom fields are deprecated, use type :json instead",

View File

@ -547,28 +547,38 @@ class Plugin::Instance
end
# Applies to all sites in a multisite environment. Ignores plugin.enabled?
def register_category_custom_field_type(name, type)
reloadable_patch { |plugin| Category.register_custom_field_type(name, type) }
def register_category_custom_field_type(name, type, max_length: nil)
reloadable_patch do |plugin|
Category.register_custom_field_type(name, type, max_length: max_length)
end
end
# Applies to all sites in a multisite environment. Ignores plugin.enabled?
def register_topic_custom_field_type(name, type)
reloadable_patch { |plugin| ::Topic.register_custom_field_type(name, type) }
def register_topic_custom_field_type(name, type, max_length: nil)
reloadable_patch do |plugin|
::Topic.register_custom_field_type(name, type, max_length: max_length)
end
end
# Applies to all sites in a multisite environment. Ignores plugin.enabled?
def register_post_custom_field_type(name, type)
reloadable_patch { |plugin| ::Post.register_custom_field_type(name, type) }
def register_post_custom_field_type(name, type, max_length: nil)
reloadable_patch do |plugin|
::Post.register_custom_field_type(name, type, max_length: max_length)
end
end
# Applies to all sites in a multisite environment. Ignores plugin.enabled?
def register_group_custom_field_type(name, type)
reloadable_patch { |plugin| ::Group.register_custom_field_type(name, type) }
def register_group_custom_field_type(name, type, max_length: nil)
reloadable_patch do |plugin|
::Group.register_custom_field_type(name, type, max_length: max_length)
end
end
# Applies to all sites in a multisite environment. Ignores plugin.enabled?
def register_user_custom_field_type(name, type)
reloadable_patch { |plugin| ::User.register_custom_field_type(name, type) }
def register_user_custom_field_type(name, type, max_length: nil)
reloadable_patch do |plugin|
::User.register_custom_field_type(name, type, max_length: max_length)
end
end
def register_seedfu_fixtures(paths)