How to add custom profile fields to a NodeBB forum ?
-
Okay so I dug a little and was searching for something like an User model to edit so I can add my custom fields, but I seem to be unable to find it. I saw a whitelist for fields, but that's all ...
Does anyone know where to start at least ? Even if it's not on the ACP & a whole plugin, it's not that big deal if I can edit the files myself.
-
@julian Sorry, just to be clear : you're writing a Developer FAQ on how to add custom fields or ... ? sorry I'm just making sure I understood right.
I'd love to write a plugin but even with the quickstart plugin, I really don't know where to start on how I could achieve custom fields -
Sorry, I'm still trying to do this and since I saw many topics on the subject, I thought I'd share my process, even if I think I'm not qualified to do this - maybe it'll help someone some day.
I found in
src\user\data.js
:User.setUserField = async function (uid, field, value) { await User.setUserFields(uid, { [field]: value }); }; User.setUserFields = async function (uid, data) { await db.setObject(`user:${uid}`, data); for (const [field, value] of Object.entries(data)) { plugins.hooks.fire('action:user.set', { uid, field, value, type: 'set' }); } };
src\user\profile.js
:User.updateProfile = async function (uid, data, extraFields) { let fields = [ 'username', 'email', 'fullname', 'website', 'location', 'groupTitle', 'birthday', 'signature', 'aboutme', ]; if (Array.isArray(extraFields)) { fields = _.uniq(fields.concat(extraFields)); } if (!data.uid) { throw new Error('[[error:invalid-update-uid]]'); } const updateUid = data.uid; const result = await plugins.hooks.fire('filter:user.updateProfile', { uid: uid, data: data, fields: fields, }); fields = result.fields; data = result.data; await validateData(uid, data); const oldData = await User.getUserFields(updateUid, fields); const updateData = {}; await Promise.all(fields.map(async (field) => { if (!(data[field] !== undefined && typeof data[field] === 'string')) { return; } data[field] = data[field].trim(); if (field === 'email') { return await updateEmail(updateUid, data.email); } else if (field === 'username') { return await updateUsername(updateUid, data.username); } else if (field === 'fullname') { return await updateFullname(updateUid, data.fullname); } updateData[field] = data[field]; })); if (Object.keys(updateData).length) { await User.setUserFields(updateUid, updateData); } plugins.hooks.fire('action:user.updateProfile', { uid: uid, data: data, fields: fields, oldData: oldData, }); return await User.getUserFields(updateUid, [ 'email', 'username', 'userslug', 'picture', 'icon:text', 'icon:bgColor', ]); };
I've also tried to read three plugins that were interesting to me, see how they did it : Cash mod, OpenFantasy & Custom Fields. But eventhough I tried a lot I haven't been able to reproduce anything they did in the quickstart plugin. Even my
console.log("hello world")
wasn't working, hahah. They're not working either anyway...I know it's not good to edit core files, but I'm really getting frustrated. If I can't add custom fields, I can't use NodeBB and I'll be back on Forumotion, which is a pain in the ass.
I thought of creating another table which would have all the custom fields and a column that would get the UID of the user those fields are related to. But I was having such a hard time finding how to show tables in MongoDB, especially user tables and switched to PostgreSQL, only to find out there isn't any user table, just data stored in a row...
So yeah, is there anyone to give me like hints on how I could do that ? I know I have to do a plugin, but I just don't know where to start and I can't seem to replicate what others did before.
Thanks
-
I thought NodeBB was trying to emulate how wordpress works, in terms of ease of extending functionality. Yet, so much confusion about adding custom fields and old plugins which don't work anymore make it harder to adopt NodeBB. Adding, retrieving, and displaying custom data for users, categories, topics, posts, groups should be easier and documented for developers who want to adopt and extend NodeBB, keeping this information so proprietary maybe a good business decision but it certainly isn't going to help expand adoption of NodeBB.
I don't see any examples of this basic extension implementation in plugin documentation, and trying to decipher how old plugins are doing it is a mess as demonstrated by so many users who gave up, by their own admission which I found upon searching this forum to learn custom fields/custom data implementation via plugins.
-
@solmak said in How to add custom profile fields to a NodeBB forum ?:
keeping this information so proprietary maybe a good business decision but it certainly isn't going to help expand adoption of NodeBB.
The information is not proprietary by any means.
How do I add custom user fields to my theme?
If you have a custom theme that introduces custom user fields into the edit page, you might have noticed that the fields don't seem to show up on the fronten...
NodeBB Community (community.nodebb.org)
I understand your frustration, but I cannot be held responsible for third-party plugins being out of date.
-
Thank you @julian you always respond and seem motivated in helping the community. By proprietary I meant no effort has been made to provide clean working examples for the latest nodebb, as in maintenance of such documentation for people jumping into nodebb to replace their old system.
You have a great product here, with so much more potential and I understand you may not have resources and funding to provide so much documentation and maintain working example of a plugin that does CRUD with custom fields/custom data, but it becomes harder for new adopters if they're unable to figure out cost effective way to replace their old platforms which have plethora of 3rd party add-ons and plugins especially dealing with custom fields and custom data.
I take the blame as well, as part of the community it is partly our job to help keep a set of quickstart plugins, documentation, help available to enhance and optimize the process for new adopters. I hope the community gets together and makes something like a curated directory of available plugins, and tags and tracks what versions each supports, and tries to keep a version that supports the latest major version updates.
Thank you for the wonderful product, I keep trying and finding an excuse to adopt it and hopefully I will get there sooner or later.