(Drupal 6.16)

Because of an issue with Content Profile (http://drupal.org/node/810992 -- at least I think it's an issue, although I could be doing something wrong), I'd like to use a SQL statement to grab the value of a field on a user's content profile node and display it on certain nodes of which the user is the author.

Right now, I have a field on the Content Profile type ("uprofile") called "field_author_bio".
On one of my other content types (let's say the standard Blog entry content type, to keep things simple), I have a computed field called "field_author_bio_display".

My SQL skills are modest, at best, and I simply do not know what code needs to go into the "field_author_bio_display" field on the Blog content type so that the author's bio (from their Content Profile node; field name: "field_author_bio") appears on the nodes they create. I've used Computed Fields before, so I understand how they work. I'm only looking for the db_query(SQL-STATEMENT-HERE) portion.

Can anyone help me out here? I'd really appreciate it. This is one of the final things that's mandatory for a project I'm working on and it's the last thing that's holding me up. (Of course, if I'm doing something wrong with regard to the issue linked in the first sentence of this support request, please let me know that and I'll do it the other way, if that's better.)

Also, note that the user is not able to edit the "field_author_bio" field on their Content Profile node. I have installed the Field Permissions module and locked that field down so that only a site admin can edit it (to control what's in the field). So, most users will have nothing in this field. Only a few will have something there. Not sure if that matters.

Thanks!

Comments

newbstah’s picture

subscribing

dmetzcher’s picture

Although I'd still love to know if anyone has the SQL to do this, I've decided to go another route. In fact, this route might be better, as it has less moving parts.

  1. I created a standard profile field, called "profile_mini_bio", using the core Drupal profile module. This field is hidden from everyone except administrators (the first radio button when creating the profile field).
  2. I created a field on the user's profile node (which is managed by the Content Profile module) called "field_author_bio". It is a Computed Field (Computed Field module). The contents of this computed field are below. I did not store it's value in the database (uncheck the option for this when creating the computed field).
  3. I added the necessary CSS to my stylesheet to make it all look nice.

Note that the code below will also pull the user's picture and structure everything. Also note that it generates the username, as a link, to the user's profile (the PathAuto module is installed and my user profile links look like: example.com/user/user-name -- without PathAuto installed and set up this way, the code below would need to be modified). This means that the profile field that contains the mini bio must have content entered into it in the following format (example below), because the user's name will be added by the code below.
--> Example: "is the founder of Acme Widgets and likes to write in her spare time. She enjoys vacationing on the moon and basket-weaving."
(Note, in the example above, that the user's name is omitted, as it should be. On my site, a user's username is the same as their actual name, but if you allow usernames like "bigbob1234", you might want to pull a real name value from their profile instead.)

Computed Field code:

// Load user.
$node_author = user_load(array('uid' => $node->uid));

// Populate variable with contents of "profile_mini_bio" field.
$author_bio = $node_author->profile_mini_bio;

// Populate variable with username.
$author_name = $node_author->name;

// Make username lowercase, replace spaces with dashes.
$author_name_url_format = strtolower(preg_replace('/[^a-zA-Z0-9\-]/si' , '-' , $author_name));

// Create link to user's profile using the username.
$author_name_link = '<a href="/user/' . $author_name_url_format . '" title="View full profile">' . $author_name . '</a>';

// Populate variable with path to user's picture.
$author_picture_path = $node_author->picture;

// Create picture with link to user's profile.
$author_picture_link = '<a href="/user/' . $author_name_url_format . '" title="View full profile">' . '<img src="/' . $author_picture_path . '" alt="' . $author_name . '" />' . '</a>';

// Add divs and create structure.
$author_bio_structure = '<div class="author_bio_picture">' . $author_picture_link . '</div><div class="author_bio_text">' . $author_name_link . ' ' . $author_bio . '</div>';

// Output the structure.
$node_field[0]['value'] = $author_bio_structure;

CSS added to stylesheet:

/* The field we are styling is "field_author_bio". It is a computed field that pulls the "profile_mini_bio" information and displays it on select nodes. */
div.field-field-author-bio { /* Style the div created by the Content Profile field. */
  font-style: italic;
  margin: 12px;
  padding-top: 4px;
  border-top: 1px dashed #ddd;
}

div.field-field-author-bio img { /* Reduce the size of the user's image. */
  width: 40px;
  height: 40px;
}

div.field-field-author-bio div.author_bio_picture { /* Style the divs created in the Computed Field code. */
  float: left;
  margin-right: 8px;
}