Continuing the discussion from Getting joined data for widget scope :
I am trying to extend the poster-name widget and add some user custom fields next to a user’s name on a post.
As per @eviltrout :
and…
whitelist_staff_user_custom_field("myCustomField") in plugin.rb
I have whitelisted the custom field I am trying to access but when I view attrs.userCustomFields of the poster-name widget it is undefined. Am I missing a step to make the user custom fields available to the widget/plugin?
Falco
(Falco)
April 28, 2016, 9:17pm
2
If things haven’t changed, you need to add user custom fields to the post serializer when you want a user custom field on the post object.
Like this:
DiscoursePluginRegistry.serialized_current_user_fields << "signature_url"
DiscoursePluginRegistry.serialized_current_user_fields << "signature_raw"
after_initialize do
User.register_custom_field_type('see_signatures', :boolean)
User.register_custom_field_type('signature_url', :text)
User.register_custom_field_type('signature_raw', :text)
if SiteSetting.signatures_enabled then
add_to_serializer(:post, :user_signature, false) {
if SiteSetting.signatures_advanced_mode then
object.user.custom_fields['signature_cooked'] if object.user
else
object.user.custom_fields['signature_url'] if object.user
end
}
# I guess this should be the default @ discourse. PR maybe?
add_to_serializer(:user, :custom_fields, false) {
if object.custom_fields == nil then
I was going off the Discourse Staff Notes plugin which uses the poster-name widget in a similar way I want to, and it doesn’t look like they do that.
Poster custom fields are empty when new post is created. Using allow_public_user_custom_field method to allow user fields.