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 committed by GitHub
parent 384a8b17a1
commit eef93ac926
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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) get_custom_field_descriptor(key).append_field(target, key, value)
end 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 if Array === type
Discourse.deprecate( Discourse.deprecate(
"Array types for custom fields are deprecated, use type :json instead", "Array types for custom fields are deprecated, use type :json instead",

View File

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