0

I hate making posts like this because I feel like I am asking people to do all my work for me! However, in times like this, when I am pressed for time, I have to.

I am trying to add an user profile in the topics in the Forum module. I have found a brilliant tutorial, but unfortunately it is for Drupal 6 and some of the functions are not compatible with Drupal 7; I couldn't find the equivalent functions, and I figured some of you may know them.

If you do, I would greatly appreciate it if you could share them with me; even if you don't provide the whole of the functions in tutorial (which would be nice), and just provide me with the Drupal 7 functions to replace the ones in the tutorial; anything would help.

The main functions that do not work are the profile_load_profile($user), and the get_user_XYZ($user) functions.

By the way, I am assuming it is because those functions are depreciated in Drupal 7 when it says "Undefined"! I can't see any other reason for it not to work, and I kind of expected some of the tutorials wouldn't work properly on Drupal 6.

2 Answers 2

2

Drupal 7 doesn't include the core profile module since users are entities which you can attach fields to. If you have added additional fields to the user you can get them with just user_load().

FYI: it is not advisable to the $user when calling user_load() since $user is a global variable which can cause problems.

It doesn't look like that tutorial would ever fully work since get_user_comment_count() is never defined and the get_user_rank() parameter call's for a comment count but uses the $user object in the user_forum_load() function.

To get the comment count of a user you could just lookup the number of comments from the comment table for a given user and the tutorial's user_comment_rank() should still work.

3
  • Hi, sorry for my slow reply. At the minute, I have just commented the two lines at fault out so that there is no error from the template file, I still can't get it to show up! There a now errors or anything, it just seems that drupal isn't taking notice of the functions! And it is the same with this tutorial! So does anyone have a working solution, or alternitive for Drupal 7. Thanks for the information @acouch!
    – Andy
    Jul 27, 2011 at 11:31
  • The tutorial you just linked to is about updating template files. What the first tutorial you linked to does is add extra data to the $user object. Once you've added to the $user object in hook_user() you need to call that either directly in the node-forum.tpl.php or comment-forum.tpl.php. If you added $user->foo in hook_user() you can call that in node-forum.tpl.php as print $user->foo() . You can check to see if your hook_user() is working by global $user; var_dump($user); in the node-forum.tpl.php.
    – acouch
    Jul 27, 2011 at 17:31
  • Sorry for the slow reply! I've just got so ****ed off trying to do this, and it's not even for me, so I've decided to bite the bullet and just install Advanced Forum. So now, I think the forum will meet my clients requirements. Thanks for your excellent support though! Now I ask myself: Why didn't I take the easy way out to start with, instead of spending hours and getting no where? A question I ask all too often!
    – Andy
    Jul 29, 2011 at 13:01
1

Drupal 6 doesn't define any function whose name starts with "get_user"; those are functions defined in the code used by the tutorial, or from a module the tutorial is referring to.

The User profile module, in Drupal 7, is only used when updating from a Drupal 6 site; differently the User profile module is not shown in the list of the modules, as it is hidden by default, and users cannot enable it using the user interface. The alternative to using the User profile module is to create fields using the user interface provided by the Field module.

2
  • You are right, those functions are defined in code used by tutorial, apart from the comment_count, which acouch has already mentioned! But, the tutorial doesn't refer to a module anyway. Does it?... It looks like I may have to use your alternitive, if nobody can put forward a better way, or a tweaked tutorial, etc. Thanks anyway
    – Andy
    Jul 27, 2011 at 11:41
  • I was precisating what I said in the first phrase: If you find a reference to a get_user_XYZ() function, but the tutorial code doesn't have the code for that function, then the tutorial is referring a third-party module, although modules should prefix a function name with their machine name, and that does not seem it done with get_user_XYZ().
    – apaderno
    Jul 27, 2011 at 14:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.