[nodebb-plugin-ns-custom-fields] NS Custom Fields


  • @andre-mosin said in [nodebb-plugin-ns-custom-fields] NS Custom Fields:

    groupTitle

    I think I am getting close:

    https://github.com/NodeBB/NodeBB/blob/master/src/posts/user.js#L90-L103

    Don't know really how to like add the field there... other then edit this file and add my custom field... but that's like a hack and I would need like create a fork of NodeBB... I might do it but I would rather fix or fork the plugin. Thanks!

  • NodeBB Admin

    @andre-mosin In the code you link there is a hook you can use to add you custom fields.

    const result = await plugins.fireHook('filter:posts.addUserFields', {
    			fields: fields,
    			uid: uid,
    			uids: uids,
    		});
    

    Write a plugin and use this hook to add the custom fields into the fields array. Also see this post.


  • @baris Thank you so much! That worked! Getting closer.. Now I am able to add the field But with no value... it is not loading the value properly from /api/user, the "customFields" value is always "null".

    I tried other fields that are native to NodeBB like "joindate" for example and it works fine.

    here is a topic:
    418b9a1a-eb43-4e7c-bb4d-cca1420d5509-image.png

    here is the user admin:
    db47016c-b4a2-4956-900f-4c80bd88c6e6-image.png

    that array is not empty... Any idea how to fix this? Thanks again!


  • so I just made it to work by adding the value of that field using another hook filter:topics.addPostData... it seems redundant code though... will have to loop through all posts and add customField for each user of each post in the topic.

    Hopefully there is a better way of doing that...

  • Global Moderator Plugin & Theme Dev

    Are you storing that field on the user object in the database? You have to if you're using the hook as baris said.


  • @pitaj said in [nodebb-plugin-ns-custom-fields] NS Custom Fields:

    that field on the user object

    Sorry I am not sure if I understood your question. Using that hook mentioned by Baris I am able to add fields to User object inside of Topic posts, however the values of the fields coming from this ns-custom-fields plugin that are inserted into api/user/$username are not getting loaded. In order to load that I have to basically add an extra hook filter:topics.addPostData and load it from database again.... from what I am understanding that's how it works because the data from the ns-custom-fields plugin is not persistent on the user's object.

    I am getting to understand the hook system and the plugins now and probably what I did has to be done unless there is a better way. I will share my code once I am done. Thanks!

  • Global Moderator Plugin & Theme Dev

    @andre-mosin sorry I made a couple big typos there. I meant to ask if you are storing the user data on the user object in the database.


  • @pitaj I was trying to figure that out and I think it is like a sub key in the user object like:

    {
    "_key": "user:1:ns:custom_fields",
    "myField": "test value"
    }

    it doesn't look like a regular field in the user object which is like this:

    {
    "_key": "user:1",
    ....
    "joindate": 1602212738594,
    "lastonline": 1602703044144,
    "status": "online",
    "uid": "1",
    "username": "admin",
    "userslug": "admin",
    ...
    "reputation": 4
    }


  • @andre-mosin ok... thanks for all the help... I probably will need more help though... lol I think I have all that I need now and I decided to change the route... I was trying to utilize existing plugins but I am having to make so many changes to the existing ones that I decided to start a new one from scratch that will include everything I need. I learned a lot from looking and trying to modify other plugins that I think it makes more sense to write from scratch.


  • Does any one have this plugin working on latest revision of nobebb . development seems to have stopped , i have messaged the creator with no reply ... is this not supported anymore ?


Suggested Topics

| | |