Hello again,
This module is great - extremely light weight and if implemented correctly could seriously reduce the load on my server. I'm trying to implement magic_tabs althrought my site! But ran into a hitch with how to load dynamic content...
After seeing your suggestion for the disappearing magic tab issue, I moved all of my functions into a custom module. This took care of my previous problems. At the end of this module, I have the following callback:
function magic_tabs_profile_callback() {
$uid = arg(1);
$account = user_load(array('uid' => $uid));
$tabs[] = array(
'title' => t('About'),
'content' => dload_profile_about_tab($uid,$account),
);
$tabs[] = array(
'title' => t('Friends'),
'content' => dload_profile_friends_tab($uid,$account),
);
$tabs[] = array(
'title' => t('Activity'),
'content' => dload_profile_activity_tab($uid,$account),
);
$tabs[] = array(
'title' => t('Tags'),
'content' => dload_profile_tags_tab($uid,$account),
);
return $tabs;
}
Notice the use of $uid and $account. I am trying to avoid loading global variables, and minimize reloading the same variables repeatedly inside of each function. The above works correctly on the initial page load (ie the first tab displays the return value from dload_profile_about_tab($uid,$account) as needed) , but fails when you click on any magic tab, even if its the same 'about' tab. Moving these lines into each dload function did not help. Seems that $uid and $account are being cleared, and hence my dload* functions do not have the data to work with beyond the initial load :(
I then tried passing the parameters into magic_tabs_profile_callback() from my tpl.php file, but magic_tabs_get doesn't allow this.
<?php print magic_tabs_get(magic_tabs_profile_callback($uid,$account)); ?>
Any help or even just an example would be greatly appreciated - how can I use functions with parameters to load the magic tab content?
Best regards,
.
Comments
Comment #1
d0t101101 commentedBTW, for a little background information to clarify what i'm trying to do here, the $account object contains info for the owner of the profile page being viewed.
.
Comment #2
yhager commentedThank you for the report.
The scenario you mention is indeed not supported by the code, but I understand the need and will work on fixing this ASAP.
Comment #3
yhager commentedI've added support for using arg() function in callbacks.
Please use the latest version (5.x-1.0) and try again.
Comment #4
d0t101101 commentedHey yhager,
Thanks A LOT for adding arg support so quickly! This fixed the issue when viewing the current users profile page - now all of the tabs work as expected. However, when viewing another users profile page, the problem persists. To diagnose it, I added the following print lines just below the variables set in my callback function:
When viewing other users profile pages, it works as expected on the first page load (ie '3 - UserName' is printed). When clicking on any of the magic tabs though, arg(1) is set to 'magic_tabs_profile_callback', and of course $account is then empty. I am unsure if these args can be overridden inside of a module - could I maybe just set another arg, like arg(123) and use it inside of the callback somehow? If not, a catch all solution might be to support a new magic_tabs_get syntax, like:
This way magic_tabs users can pass whatever they want into the callback function, and aren't limited to only args. In the immediate though, I would be happy to continue to use args if I can get them to work as needed :)
FYI - I don't know exactly how drupal handles args internally yet, so I might be missing something easy here...
Best regards,
.
Comment #5
d0t101101 commentedI spent a few hours trying to find a workaround for this, but came up empty handed. I'll definitely report a solution here once found.
An interesting side note on this - the description of the problem above only applies to authenticated users. If you browse profile pages anonymously, the custom magic_tabs callback works for all user profiles... Strange! And if your authenticated, arg(1) gets set to the callback name when browsing other users profile pages.
.
Comment #6
yhager commentedYes, I can recreate the problem and am checking for a solution.
The "catch all" solution you described is not going to work, since while serving the ajax call, the path is different and setting it right before the callback is what I am trying to do.
Comment #7
d0t101101 commentedI really appreciate the help,
Best regards,
.
Comment #8
d0t101101 commentedThe latest release (v1.1) resolved this, too. Magic_tabs is working very well on my user profile pages, for both authenticated and anonymous users. Thanks a bunch for contributing such an excellent module :)
Best regards,
.
Comment #9
d0t101101 commentedThanks yhager!
Comment #10
Anonymous (not verified) commentedAutomatically closed -- issue fixed for two weeks with no activity.