[nodebb-plugin-ns-custom-fields] NS Custom Fields
-
@Nicolas said in [nodebb-plugin-ns-custom-fields] NS Custom Fields:
Provides full set of instruments to create custom fields in user's profiles: admin control panel (manage available fields), user account (edit and view fields);
Install
npm install nodebb-plugin-ns-custom-fields
ACP
Preview of Admin Control Panel for Custom Fields Plugin,
ver. 1.0
Theme Status
Currently zero themes support this plugin. With template engine of NodeBB, some changes should be made manually to the theme, if you want to see custom fields in the user's profile.
It will look like:
Why I can't see the the custom field page after install the plugin via the admin install plugin. I tried rebuild and restart the server. Where does it located?
-
I update the version from 5.x.x to 6.0.0 which 5.x.x installed via admin plugin portal. I can see the custom field plugin under the "Plugin" of admin portal.
A new issue, I added some custom fields, but it does not show in user edit profile page /user/xxxxx/edit. Any one can help?
NodeBB version: v1.12.2
-
@Fei-Wong said in [nodebb-plugin-ns-custom-fields] NS Custom Fields:
page /user/xxxxx/edit
There should be one more button under the avatar.
-
Hello,
This plugin seem to be working good on v1.13.4-5. I can add fields, change them throgh the user profile... and I can see fields are exposed to the api/user/$username so it is easy to add to that specific template... /user/$username
I am new to plugin and theme development for NodeBB... I am having a hard time to make like the custom fields be available on other pages template such as topi.tpl for example.
On the Topic API you have information about the user like as follows.. my goal is to expose some or all custom fields there so I can add them to topic.tpl. Any idea how or where I can make that happen? ANY help is appreciated. Thanks!!
"user": {
"uid": 1,
"username": "admin",
"userslug": "admin",
"reputation": 4,
"postcount": 51,
"topiccount": 51,
"picture": null,
"signature": "",
"banned": 0,
"banned:expire": 0,
"status": "online",
"lastonline": 1602618059671,
"groupTitle": "["administrators"]",
"groupTitleArray": [
"administrators"
],
"icon:text": "A",
"icon:bgColor": "#673ab7",
"lastonlineISO": "2020-10-13T19:40:59.671Z",
"banned_until": 0,
"banned_until_readable": "Not Banned",
"selectedGroups": [],
"custom_profile_info": []
}, -
@andre-mosin said in [nodebb-plugin-ns-custom-fields] NS Custom Fields:
groupTitle
I think I am getting close:
NodeBB/src/posts/user.js at master · NodeBB/NodeBB
Node.js based forum software built for the modern web - NodeBB/src/posts/user.js at master · NodeBB/NodeBB
GitHub (github.com)
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!
-
@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:
here is the user admin:
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...
-
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!
-
@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.
-
This would be very useful to most folks, I reckon. Can someone please guide me as to how I can make this compatible so I can do the same?