Started work on a tutorial

Events happening in the community are now at Drupal community events on www.drupal.org.
michelle's picture

I started working on using all these modules to build a fancy profile and quickly got lost. I did a lot of searching and there's information out there but it's pretty scattered. If there's a tutorial outside of the readme files, I missed it. So I've started writing one as I go along. It's far from finished, but it's a start. I'm posting the link in case what I've done so far helps anyone. Once it's done, I'll put it on drupal.org. For now, it's on my site:

[Link deleted]

If you notice any errors, please let me know. It's working for me so far, but I had gotten a ways into it before going back and writing up what I did, so I might have goofed something up.

Michelle

Update March 24, 2007 I decided to simplify my tutorial and not include some of the more advanced stuff I was originally planning. I realized that talking about theming it really was more CCK specific than nodeprofile specific and getting into the whole searching profiles thing was more into views, etc. So I decided to go with just the basic instructions for setting up 1 user = 1 profile page. You can find the tutorial in the handbook now:

http://drupal.org/node/130756

Comments

Tutorial looking good - thanks Michelle!

Walt Esquivel's picture

I took a quick glance at your write-up thus far, and I was able to quickly pick up a few helpful tips.

I'll look at following your steps later this week and will post here any suggestions.

Thank you!

Walt Esquivel, MBA; MA; President, Wellness Corps; Captain, USMC (Veteran)
$50 Hosting Discount Helps Projects Needing Financing

Walt Esquivel, MBA; MA; President, Wellness Corps; Captain, USMC (Veteran)
$50 Hosting Discount Helps Projects Needing Financing

Sounds good

michelle's picture

Glad you've found it helpful. I'll keep fleshing it out and adding more steps as I get to them and hopefully have something worth putting in the handbook when it's done.

Michelle

hm, yes nice start. You

fago's picture

hm, yes nice start.
You should state that you are using the simple approach without pageroute, which means that each profile consists only of one node.
However the way you included the edit tab isn't that nice.

I'm using separate menu items for providing a edit profile menu entry.

But if you want to have the edit tab I see two ways to get a better solution. Both ways assume you have only one nodeprofile (nodeprofile does allow you to create more than one..)

  • One solution is to directly link to the profilenode instead of linking to the usernode. That could be done by adapting the theme_username function a bit

    • Another solution would be a small custom module, that creates your tab for usernode. But perhaps it would fit better to /usernode, so that it is editable at /usernode/edit.

I could provide the code for one of both solutions if you want..

Other code

michelle's picture

I'd love to see the code for linking directly to the profilenode. What I'm wanting is for an empty profile to be created automatically for each user. In my case, I only need one profile per user, so a simple one to one relationship is fine. The key for me is that it needs to be automatically created and I thought I needed usernode for that. I've only been looking at this for a couple days, so I wouldn't be surprised to find there's a better way I've overlooked.

I didn't like the idea of having separate menu items, though. I think having a view profile link to a node with a bad edit tab and a separate edit link off the menu is too confusing for my intended users.

As to pageroute, I may get to that eventually. I'm starting out simpler to learn this but may want the extra functionality at some point. If I do, I'll make another tutorial. :)

Thanks,

Michelle

PS: I should mention that I can only work on this when my toddler is napping or otherwise occupied, so stuff from me will come in spurts as I get a chance to get at the computer.

To link to nodeprofile

bfbryan1811's picture

Follow the directions in the readme:
* If you don't like the usual node forms for editing the profile remove the usual
'create content' link using the menu module. Use a new link pointing at
'nodefamily/CONTENT_TYPE' or an url alias of it.

As for automatic empty profile you can use usernode to do that for you and theme it how you wish. Every time a new user registers it should create a usernode and a nodeprofile. What I found confusing in all SOC '06 code was why can't we user usernode and profile to create the same functionality? This way a user can update his/hre 'account settings' and 'profile settings' all in one spot: user/edit

...

michelle's picture

Thanks for answering but that's what I'm already doing...

Michelle

profile nodes aren't

fago's picture

profile nodes aren't automatically created!! (I think this approach has some disadvantages!)
My modules just present an add or edit form at the same page, so the user doesn't even notice if he adds or edits a node..

You could disable the "wrong" edit tab for your users easily by don't giving them edit-permission.

I'll have a look at the code for your links..

Oooh, good point

michelle's picture

Since the usernode is autocreated and I created a nodeprofile before linking them, I hadn't looked into what would happen if I tried going to the usernode of someone without a nodeprofile. Just tried it and it errors. Oopsie. I need to work around that bit.

Well, I did say this tutorial was a work in progress. LOL

I don't like the idea of disabling the edit tab. My method of putting the correct link on the edit tab seems much more user friendly. If there's a downside to hacking that link, I haven't hit it, yet. Is there some reason you're so against it? Is it going to come back and bite me in the behind later? :)

Thanks,

Michelle

Part way there...

michelle's picture

Ok, so I got rid of the error by changing the node-usernode.tpl code to:

<?php
  $children
= nodefamily_relation_load($nid);
  if (empty(
$children)){
    print
"This user has not yet created a profile.";
  } else {
    print
node_view($children[0]);
  }
?>

The last sticky bit there is that if you are the user and look at your own node, it's not very clear that you need to click on the edit tab to create your profile. The simple way would be to change the tab name to "Create/Edit profile" instead of just "Edit" but I'm not sure that's the most user friendly way. I'm going to do that for now because it's easy and think on it some more...

Thanks,

Michelle

I'dont like it because it's

fago's picture

I'dont like it because it's a hack. Better write a small module that creates a tab for each nodeprofile "edit profile_1", "edit profile_2", ..

code..

fago's picture

here is code for directly linking to the profilenode, for 5.x:
I've not tested it, but it should work that way. Please try it.
Replace your_content_type with the machine readable name of your nodeprofile content-type...
If there is no such profile, it will link to the usernode nid...

<?php
function phptemplate_username($object) {

  if (
$object->uid && $object->name) {
   
// Shorten the name when it is too long or it will break many tables.
   
if (drupal_strlen($object->name) > 20) {
     
$name = drupal_substr($object->name, 0, 15) .'...';
    }
    else {
     
$name = $object->name;
    }

    if (
user_access('access content') && module_exists('usernode')) {
     
$nid = usernode_get_node_id($object);
     
$children = nodefamily_relation_load_by_type($nid);
         if (isset(
$children['your_content_type'])) {
          
$nid = $children['your_content_type'][0]->nid;
         }
     
$output = l($name, 'node/'. $nid, array('title' => t('View user details.')));
    }
    else {
     
$output = check_plain($name);
    }
  }
  else if (
$object->name) {
   
// Sometimes modules display content composed by people who are
    // not registered members of the site (e.g. mailing list or news
    // aggregator modules). This clause enables modules to display
    // the true author of the content.
   
if ($object->homepage) {
     
$output = l($object->name, $object->homepage);
    }
    else {
     
$output = check_plain($object->name);
    }

   
$output .= ' ('. t('not verified') .')';
  }
  else {
   
$output = variable_get('anonymous', 'Anonymous');
  }

  return
$output;
}
?>

Awesome! Looks like

brenda003's picture

Awesome! Looks like everyone's beating it to me on the step by step - but that's good! I think having a simple step by step is a good key, but covering things like pageroute and the other modules that aren't mentioned as often would be good, too. What gets most people confused is just the simple set up itself, though, I think.

Step by steps

michelle's picture

I think there's room for lots of step by steps with this since there's so many things you can do. I'm posting the steps for what I am doing as I go, but there's other ways I haven't looked into like that pageroute module. So having multiple tutorials isn't a bad thing. :)

Michelle

Big revision

michelle's picture

I just did a big revision and included some things I've run into since writing the first draft. I also changed my theme to box_grey for now since it was hard to read it on the old theme.

I haven't given it a good proofreading because my toddler wants to play. I'll check back later to see if there's any new comments and go over it again.

Michelle

Looks great! I'll sit down

joachim's picture

Looks great!
I'll sit down with it tomorrow and go through it step by step.

I think part of the confusion that surrounds these modules is the terminology. There's a profile, a node you use as a profile, and so on.
I'm a bit confused by this line in your page:

'To get this, we need to tell Drupal to fill the usernode in with the User Profile node'

What's the usernode and what's the User Profile node?
I was following it great till then!

Added

michelle's picture

I added definitions to the top of the tutorial. Thanks for the feedback. :)

Michelle

Sorry, I'm even more

joachim's picture

Sorry, I'm even more confused now!

'Usernode - This node type is created by the Usernode module. The module takes care of automatically generating one usernode per user. This node contains no content and only serves to link a user to a node. You can find out more about this in the Usernode readme.txt file.'

I thought the Usernode module created a node per user of whichever type I marked with the checkbox in the Content Types management?

I thought the Usernode

michelle's picture

I thought the Usernode module created a node per user of whichever type I marked with the checkbox in the Content Types management?

No, it doesn't. It creates a node of type usernode, as provided by the module. The checkbox only sets your node as a child node of the usernode. It doesn't replace the usernode itself.

Michelle

Thanks for clearing that

joachim's picture

Thanks for clearing that up!
This is slowly starting to make sense to me. :)

I'm getting an error when I

joachim's picture

I'm getting an error when I add the node-usernode.tpl.php file to my theme folder:

* warning: include(./themes/garland/node-usernode.tpl.php) [function.include]: failed to open stream: Permission denied in /home/joachim/public_html/drupal-5.1/themes/engines/phptemplate/phptemplate.engine on line 397.
* warning: include() [function.include]: Failed opening './themes/garland/node-usernode.tpl.php' for inclusion (include_path='.:/usr/share/php:/usr/share/pear') in /home/joachim/public_html/drupal-5.1/themes/engines/phptemplate/phptemplate.engine on line 397.

usernode and cck

edex13@drupal.org's picture

i already read the tutorial at http://drupal.org/node/130756 on how to create one user = one profile page.

in the readme text for usernode mention

Notes:
The usernode itself is empty. It's just a placeholder for its user.
The usernodes of blocked users are set to unpublished.
Manual deletion of usernodes (without deleting its user) 'll be prevented.

is there will be problem if i skip the steps in the tutorial and just add field using cck straight into usernode?

Depends...

michelle's picture

That's actually what I ended up doing in the end. You'll be able to read more about it at http://groups.drupal.org/node/3724 when I'm able to get more computer time.

The main issue is that you can't have required fields in the profile if you ever have someone besides the user edit it as they'll be forced to fill in the required fields. You also lose any ability to have a multi node profile down the road. If those are ok then, yeah, works fine.

Michelle

Has there been ....

mimhakkuh's picture

any update to the attempt of a "recipe", the user "Olio" has started?

(http://drupal.org/node/130756)

... it was about erasing the usernode elements (header, tabs). i tried to adapt his solution, but i am really not sure, how to import his code int my template.php file. i am getting various error reports includint that the "-" symbol in my templates name (for the function) is not accepted ...

thx in advance - i really have to get rid of those usernode elements :)

The what?

michelle's picture

Sorry, I have no idea what you mean by "usernode elements". A usernode is just an empty node that you can use to make views work with users.

Thanks for the pointer to that handbook page, though. I never did go back and update it with the proper link.

Michelle

First I followed

mimhakkuh's picture

... the mentioned Tutorial. After adapting it, a click on a User's Name directed onto his Usernode, which was displaying 2x the Headline (Username). I found that beeing redundant, and wanted to get rid of those. As "Olio" put it in her/his comment:
I wanted to get rid of the whole header of usernode, including the title (displaying the username) and the usernode tabs because.
By now I chose to go the way of the "Shell Multimedia" Tutorial, so this posting of mine can be ignored. Thanks for taking the time to answer it ... F.

Old tutorial

michelle's picture

Yeah, that tutorial is outdated. I wrote that one within days of finding and figuring out how to use usernode / nodeprofile. Then the new version of nodeprofile came out and was much better and I ended up totally redoing it. Then I promptly forgot about the original tutorial. :) I went back and changed the update notice on the top to point to the new tutorial.

Thanks for reminding me about it,

Michelle

Profiles as nodes

Group organizers

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: