Skip to Content Skip to Menu

Please help with a Community Builder Maps Plugin

1 year 3 months ago - 1 year 3 months ago #334318 by quantumgravity
Please help with a Community Builder Maps Plugin was created by quantumgravity
Hi,

This is a different question for me.  I'm relaying a question from JoomUnited, who produce a nice Maps plugin that renders a map in a profile tab for each user.  I've used a similar extension for years, but that developer has faded and decided not to update their extension for Joomla 4.  This one (My Maps Location) works better, but my testing has prompted one question that they have for you.  I think they've tried to ask through another part of the forum, but I offered to ask the question for them.  

The extension does a great job with existing users, and updates their map properly if you edit the address of a user.  The problem comes with adding a new user.  They can't find the user ID created by Community Builder when a new user is added from the back end, so they can't create their map record for that user properly--they use the user ID to connect the map record to the CB user record.

With that lead-in, here is their question:

Subject: Unable to get user id on insert when integrating third party extension my map locations.

Message: 

Hello Sir,

Our My Maps Location extension integrates with Community Builder to produce maps on a profile tab.  Unfortunately, when I save a new user, saveRegistrationTab is not working.  (Note: in this use case, users are always saved in the back end; registration is not allowed.)  It is calling saveEditTab function, only there userid is not saving properly and it will give null only.  Please let us know if there are any changes in api or anything that would guide the my map location developer so they can modify existing code.  Attached is the plugin for Community Builder.  On line 695 and 745 you will see how my map location is saving data.  It is using all standard code provided by Community Builder and has been working for a very long time.

Thank you!
 
Attachments:
Last edit: 1 year 3 months ago by quantumgravity. Reason: Change reference from Joomla 3 to Joomla 4.

Please Log in or Create an account to join the conversation.

  • krileon
  • krileon
  • OFFLINE
  • Posts: 48419
  • Thanks: 8274
  • Karma: 1443
1 year 3 months ago #334320 by krileon
saveRegistrationPluginTabs only applies to registrations and it's only meant for tabs with their own field storage processes. saveEditTab is for profile edit saves and again should only be used for tabs with their own storage processes. Below is the PHPDoc for both.

saveRegistrationPluginTabs
Code:
/** * Saves the registration tab/area postdata into the tab's permanent storage * * @param TabTable $tab the tab database entry * @param UserTable $user the user being displayed * @param int $ui 1 for front-end, 2 for back-end * @param array $postdata _POST data for saving edited tab content as generated with getEditTab * @return string|boolean Either string HTML for tab content, or false if ErrorMSG generated */ public function saveRegistrationTab( $tab, &$user, $ui, $postdata )

saveEditTab
Code:
/** * Saves the user edit tab postdata into the tab's permanent storage * * @param TabTable $tab the tab database entry * @param UserTable $user the user being displayed * @param int $ui 1 for front-end, 2 for back-end * @param array $postdata _POST data for saving edited tab content as generated with getEditTab * @return string|boolean Either string HTML for tab content, or false if ErrorMSG generated */ public function saveEditTab( $tab, &$user, $ui, $postdata )

For both they should be using $user which should be populated fine with their user id. It can be accessed as follows.
Code:
$userId = $user->getInt( 'id', 0 );

Their usage of saveEditTab isn't doing anything with $user and isn't setting an id like their saveRegistrationTab implementation is. Don't expect user id to exist in the post data. Work with the $user object directly so ideally pass it to saveMMLField.


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.
The following user(s) said Thank You: quantumgravity

Please Log in or Create an account to join the conversation.

1 year 3 months ago #334328 by quantumgravity
Replied by quantumgravity on topic Please help with a Community Builder Maps Plugin
Hi Kyle,

Of course I'm completely lost on the technical side of this issue, but I hope I can fulfill the role of a go-between and get this fixed.  I really like this CB plugin.

I'm attaching an image that they supplied of their modified code, but they tell me the user ID is still showing zero.  Could you please look at it?  I really appreciate your help, as always.

(One place I'm confused is that the problem happens with a new user, not an edited user ... but you don't need to answer that.  I just want to be sure I make it clear that's where the issue arises.)

Thanks again,

Kip
Attachments:

Please Log in or Create an account to join the conversation.

  • krileon
  • krileon
  • OFFLINE
  • Posts: 48419
  • Thanks: 8274
  • Karma: 1443
1 year 3 months ago #334329 by krileon
The problem is they're completely using the function wrong. User ID doesn't exist in $postdata. Use the $user object to interact with the user. $postdata only contains the literal POST of the form, which is fine if that's what you need to get (e.g. if the tab has a custom input and you need its value). Their saveMMLField function should be modified to accept the $user object and to work with the $user object directly.

Both saveRegistrationTab and saveEditTab should be using the below to get the user id.
Code:
$userId = $user->getInt( 'id', 0 );

I have tested both of these on frontend as working as expected just now. If there's a situation where it's outputting 0 then please provide the steps you're taking when it does (e.g. backend registration? backend user edit? frontend registration? frontend user id?).


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.
The following user(s) said Thank You: quantumgravity

Please Log in or Create an account to join the conversation.

1 year 3 months ago - 1 year 3 months ago #334389 by quantumgravity
Replied by quantumgravity on topic Please help with a Community Builder Maps Plugin
Hi again Kyle,

JoomUnited has tried but still seems to be outputting "0" for User ID on backend registration.  Honestly, it's a very good CB plugin and provides quite a bit of added value for CB users like me if we can just get them past this backend registration issue.  There's a little bit of a language barrier, so that may cause an issue.  

To try to beat that problem, they've supplied a 3-minute Google Drive video of the steps they're taking:
drive.google.com/file/d/1iu_Pz4jcUOoZYLKl7gcizN5q8qUxXQ7N/view?usp=sharing

Just four seconds in, I see that for saveRegistrationTab they're using:
Code:
$postdata['id']=$user->getInt( 'id', 0 );

I've attached a screenshot of that entire section of code in case it saves you any time.

Thanks so much for your patience and help with this.  

Kip
 
Attachments:
Last edit: 1 year 3 months ago by quantumgravity. Reason: Removed a reference to an alternative OneDrive link, which didn't work.

Please Log in or Create an account to join the conversation.

  • krileon
  • krileon
  • OFFLINE
  • Posts: 48419
  • Thanks: 8274
  • Karma: 1443
1 year 3 months ago - 1 year 3 months ago #334395 by krileon
Backend saves are different from frontend. They don't go through the same storage processes and bypass a lot of validation and are more like direct stores for administrative purposes.

The saveRegistrationTab and saveEditTab functions are actually legacy code. They're not used anymore and they were originally implemented for frontend only. Their implementation really should be using triggers instead of these functions. Specifically the following.

Backend
Registration = onAfterNewUser
Edit = onAfterUpdateUser

Frontend
Registration = onAfterUserRegistration
Edit = onAfterUserUpdate

Have retested and confirmed saveRegistrationTab does not apply to backend. Backend is usually always considered an "edit" state. saveEditTab does apply to backend, but it does so before the user is created. This is why the user id is always 0.

While this is legacy code that shouldn't be used anymore will go ahead and fix this behavior, but their integration should really really be using triggers. We've documentation for triggers below. In CB 3.x all this legacy API will gradually be removed.

www.joomlapolis.com/documentation/279-community-builder/tutorials/18358-using-cb-triggers

Have created a bug ticket below. Will try to have a fix out today or by end of week.

forge.joomlapolis.com/issues/9219

Note for backwards compatibility reasons saveEditTab must still run during backend user registration. Their implementation should just skip its behavior if the user id is 0.


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.
Last edit: 1 year 3 months ago by krileon.
The following user(s) said Thank You: quantumgravity

Please Log in or Create an account to join the conversation.

Moderators: beatnantkrileon
Powered by Kunena Forum