First, thanks for developing this well written and well thought out module.

I've been using the latest beta releases for a while now, and while it's been working fine, I'm not too happy with the implementation on user pages. I wanted to have only one content type designated for profiles, and have the content of those nodes more tightly integrated user pages, exactly as it is displayed on node/#.

Well, I started hacking away trying to achieve just that, and found it fairly easy. Some hours of happy hacking later, I ended up with a complete little module (content_profile_page for lack of a better name) with a couple more features than planned. It's straight out of the oven, so there be bugs.

The settings of the module are...

Show on user page:
Content from the selected content type will be shown on user pages. Select Default to show the default user page.

Default edit:
Select which subtab the Edit tab should default to on user pages.

Redirect profile nodes to user page:
If checked, a user's profile node will redirect to the user's page. This is useful if you don't want profiles to appear in two places (node/# and user/#).

It works with more than one content type set as content profiles, but it allows you to highlight one of the content types on user pages, plus redirects from the nodes so that it's all in one place. The Default edit option felt obvious, as the profile is something you'd want to edit more often than your account information.

If you think some of these are useful features, feel free to take bits and pieces out of the module and/or rewrite them for Content Profile. It wouldn't feel right to publish this as another contrib module, as it doesn't provide that much in addition to Content Profile, so I thought I'd just post it here and hear what you have to say.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

solutiondrop’s picture

Thanks ximo, the redirect profile nodes to user page is really useful. I'll so far I haven't noticed anything wrong with that part of the module.

JohnFilipstad’s picture

Status: Postponed (maintainer needs more info) » Needs review

Just tested all the possible options and the module is working as promised. Thanks ximo! I've been wanting this! Remind me to buy you a beer in DrupalCamp Stockholm for these additional features :-)

I do hope that this be added as a sub-module of the great Content Profile module. If not, I hope ximo considers on maintaining it as a supplementary module.

...and thanks to the maintainer/s of the Content Profile module for a job well done :-)

I think d.o's recent changes on project statuses do not reflect the status of this issue now. Changing the status to 'needs review'

andreiashu’s picture

Hi,
For this module to work with the latest versions of CP I changed
$type = 'user/%user_category/edit/'. $type;
with this
$type = 'user/%user/profile/' . $type;

About the "Default edit" option: I'm not very sure it is the right approach here because you(or oven the admin) cannot edit your base user settings if you enable it. I would be nicer if you could have your base edit settings merged with the profile edit settings. Not sure if it is possible though.

I would also suggest adding

dependencies[] = content_profile
package = "Content Profile"

to the .info page.

The function content_profile_page_override_access i would have written as this:

/**
 * Access callback.
 */
function content_profile_page_override_access($account) {
  $node = content_profile_page_user_profile($account);
  // First check if the user has permission to view profiles at all.
  $access = user_view_access($account);
  if($node) {
    $access = ($access && node_access('view', $node));
  }
  return $access;
}

I'll attach the archive with the new changes in the next comment.

andreiashu’s picture

Status: Needs review » Needs work
FileSize
2.18 KB
1.8 KB
andreiashu’s picture

Status: Needs work » Needs review
andreiashu’s picture

content_profile_page_override_access would be even better written as:

/**
* Access callback.
*/
function content_profile_page_override_access($account) {
  // First check if the user has permission to view profiles at all.
  $access = user_view_access($account);
  if($node = content_profile_page_user_profile($account)) {
    $access = ($access && node_access('view', $node));
  }
  return $access;
}

:)

fago’s picture

Status: Needs review » Needs work

So what's the actual patch to look at? Can you please summarize the changes of it?

ShutterFreak’s picture

Subscribing as I also need this.

One suggestion I would add is adding a way to lock the title of the profile node and copy/sync it with the user name (or any other combinbation of (tokenized) user fields).

Cheers,

Olivier

altparty’s picture

Category: task » feature
Issue tags: -Usability

Thanks for this mod. I use 2 content types to build a user profile and it makes no use to view the nodes themselves. When I use this solution (http://drupal.org/node/244004) some features within the author pane (like UR of Privatemsg link) don't work anymore. Also the links of the nodes won't show up.

With your module these problems don't exist.

Liliplanet’s picture

Nice module! Thank you! Solves all the problems of redirecting the content profile nodes to the user page.

rangerfrex’s picture

Thanks, I am into this thing too

ShutterFreak’s picture

Regarding #8, this works with the "Automatic Nodetitles" and "Token" modules. Just set the title to the token "[author-name]" and you're done.

ximo’s picture

Status: Needs work » Active
Issue tags: +Usability

Seeing how popular this little module turned out to be, I'm considering taking it out of the issue queue and showing it some love.

Fago: Is this something you could see being included in content_profile itself? Or do you prefer that I provide this as an additional module in contrib? And maybe further down the road include it into content_profile as a sub module, if it turns out to be popular enough. I think this functionality is useful in most cases, as end users aren't aware of the distinction between a user account and a profile node and are used to seeing these in one place. I believe functionality like this is well worthy of being provided by content_profile itself. In any case, I'd like to work on getting this functionality easily available.

Liliplanet’s picture

Wonderful!

I don't know if this is the correct place, but would it be possible to move the user image into the content profile? (that is instead of the user account (edit) page ..

.. or maybe as a separate tab

Members are just not going to look for it there :)

Most appreciate your module, and again, thank you.

Lilian

andreiashu’s picture

+1 for #13

OFF’s picture

COOL! Very Very cool!

ximo, big thanks

OFF’s picture

but i dont understand why statistics counter dont count profile node views

jthomasbailey’s picture

Subscribing

mr.alinaki’s picture

Yahoo!!! Very cool! Big thanks! Now I can implement all I want :)

fago’s picture

Category: feature » task
Status: Active » Needs work

@#13: I think it would be best added as a small separate module - as separate sub-module of cp. So if you could polish it a little bit more, I'd be happy to include it!

* Please add a README.txt and some basic usage docs.

@code: I did a first quick review:
* // Fetch all content types, keep only those marked as content profile.

There is API function for that, I think it's called content_profile_get_types().

* "-default-" is a valid content type name isn't it? -> That might lead to troubles. Perhaps just use "0" as value for default.

* @content_profile_page_override_access(): Have a look at the access callback. If node_access() returns false, just the global user page access is returned, isn't it? So people might view the node? (Access violation)

pribeh’s picture

I'm not sure if this is the expected result or a bug of this submodule but after having installed the module (from #4) in its own directory (modules/content_profile_pages) user/* always redirects to the profile node. I thought the purpose of this module was to redirect links to the profile node to the user profile. Perhaps this is a conflict with panels as I'm using panels 3 in conjunction with CP, APK, & AP to display the profile. Thanks for your efforts andreiashu.

perarnet’s picture

Would it be possible to integrate unblock/publish block/unpublish functionality to this submodule? As it is now, it is annoying that we need to both publish and unblock the user in two stages.

hefox’s picture

Was wondering if content profile already had the redirect feature, but looks like it didn't being that you made this profile.

Looked at the code briefly; I've actually done something similar before and plan to do something similar again, but you've done it completly differntly from how did so couldn't be lazy and copy and paste.

Just a suggestion instead of drupal_goto in the view, make a dependcing with path_redirect module and add a link between node/ and user/ in op 'insert', 'update'. Haven't looked into pros and cons, but may be a better way. (ie don't have to go through the partial lode of the node before redirection).

Here's how I did it with path_redirect, assuming content type named profile.

$path_redirect = array('path'=>'node/'.$node->nid, 'redirect'=>'user/'.$node->uid);
                       if ($node->type == 'profile' && !db_result(db_query("select rid from {path_redirect} where path='%s' and redirect='%s'",$path_redirect))) path_redirect_save($path_redirect);
Maedi’s picture

*subscribing*

prdsp’s picture

This module no longer works with the latest RC1 or Dev versions of panels and ctools. It blocks panels from overriding the user page. Can anyone create this module just to perform the profile node redirection without the Show on user page or the default edit options. I believe the show on user page is what is causing panels not to be able to override the user page...however, all I need is the redirection. Can anyone help me with this?

hefox’s picture

The code you want is in $op 'view' of it's hook_nodeapi.

Alternatively if you're using path_redirect already, you could try out what I mentioned in #23

something along the lines of

function <some module>_nodeapi(etc.) {
  switch($op) {
   case 'view':
   // the code from the module
   break;
   case 'update':
   case 'insert':
   // or could try the code from #23 
   break;
 }
}


prdsp’s picture

Hefox - I've installed and enabled path redirect but where am I supposed to put the code that you referenced in #23

hefox’s picture

Create a module (or use a custom module for your site; I generally have one per site personally).

Replace with that module name and with content type name of the profile. (If multiple profiles replace
$node->type == ''
with in_array($node->type,array('ct1','ct2','ct3')) with ct1,ct2,ct3, being the content types (ie the machine readable name).
Blah, forgot to mention will need to resave the nodes (little details like that I forget, sorry) XD; I'd likely use views bulk operations to do something silly like update the update date.

function <module name>_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
  switch($op) {
   case 'update':
   case 'insert':
   $path_redirect = array('path'=>'node/'.$node->nid, 'redirect'=>'user/'.$node->uid);
                       if ($node->type == '<content type>' && !db_result(db_query("select rid from {path_redirect} where path='%s' and redirect='%s'",$path_redirect))) path_redirect_save($path_redirect);
   break;
   }
}

Essentially it says if this is right content type and there's not already a redirect between path and redirect, add it in on insert/update.

jthomasbailey’s picture

Category: feature » task
Issue tags: +Usability

That custom profile redirect module works great... but does anyone know how to display the content profile's comments?

theusualsuspect’s picture

This module works perfectly... It is deeply appreciated, thank you so much! It took me months so far to get a hold of user profiles in Drupal. It is such a hassle. Especially when you have 2 or more different user profiles. Anyways this module solved a big problem. So now I have my desired Profile page.

For anyone who is interested:

With Views you can create a totally customized profile page with all the CCK fields of your content profile. Just add to your view the path user/%1 with the User:UID argument. That way your profile page is overridden with the view.

@hobgobbler. You can create a separate view with an Argument User:UID retrieved from your url and then output the comments of that user. Then embed your view in page-user.tpl.php . This way I managed to output the regular user profile (as explained before) and add optional information like comments by that user, flags and posts by that user.

@Liliplanet: You can replace the core user picture with a content profile field by creating a user-picture.tpl.php file and replacing it with the following code (adapt to your needs):


<div class="picture">
<?php $avatar = $content_profile->get_variable('profile', 'field_profile_avatar'); ?>
			<?php $avatar_title =  $content_profile->get_variable('profile', 'title'); ?>
			
			<a href="/user/<?php print $avatar[0]['uid']; ?>" title="<?php print $avatar_title; ?>" class="user-picture">
				<?php print theme('imagecache', 'user-thumb-small', $avatar[0]['filepath'], $avatar_title); ?>
			</a>
</div>

This way I have access to $user-picture in my templates but it is automatically replaced with the content profile avatar. My profile page is overriden by a view, so I will only see the content profile picture fields. However, you will wind up with two picture fields on your user edit page. One in the profile edit and the other in account settings. To tackle this I simply added this to template.php


function theme_user_profile_form($form) {
  $output = '';
  // Print out the $form array to see all the elements we are working with.
  //  $output .= dsm($form);
  // Once I know which part of the array I'm after we can change it.

  unset($form['picture']);

  // Make sure you call a drupal_render() on the entire $form to make sure you
  // still output all of the elements (particularly hidden ones needed
  // for the form to function properly.)
  $output .= drupal_render($form);
  return $output;
}

The only downside is that when I print out the $user-picture in my template I will have one imagecache preset to work with. This works for my needs.

Hope this helps other developers who were looking to accomplish something similar.

Thanks again for this little, but very helpful module.

mattiasj’s picture

This helps out alot, I have recently been debating alot about how to redirect users when browsing to the user node vs the user. But what will happen when browsing a user node that currently doesnt have a registered user connected to it?

rickh’s picture

suspect

I was wondering if you could clarify the code above, as i've been looking for this for a while. It's probably clear already, and therfore sorry for the inconvenience but i'm new to drupal so the coding still gets me. I have been looking for this solution for ages so any help would be appreciated specifically concerning the fields amrked in red.

thanks for any help. r

rickh’s picture

sorry guys,

any help on this issue?

thanks, rick

rickh’s picture

For anyone else who couldn't find a way to link the user to their profile, by creating a user-profile.tpl.php file in your subtheme and placing the following code there, works like a charm.

<?php 
  if (arg(0) == 'user' && is_numeric(arg(1))) {
    $loggeduserid = $user->uid;
    $vieweduserid = arg(1);
      $node_profile = content_profile_load(profile, $vieweduserid);
      if ($node_profile->nid) $path = 'node/'.$node_profile->nid;
      drupal_goto($path, NULL, NULL, 301);
  } 
?>

Hope this helps someone

YesCT’s picture

seems like for a while there it looked like this might be added as a sub module to content profile
and that it would add the ability to redirect the profile nodes back to the user page.
is this still possible? (possible to do, and is it still on the todo list to add the functionality officially into content profile... i really dont want to do a patch or an custom module like this when it would be better maintained publicly)

chules’s picture

How do you install this? You place content_profile_page under modules but what about the patch. I am new to drupal and just need some clarification

Thank you - chules

YesCT’s picture

I guess this didn't make it in with regards to fago's comment in #20?

I dont understand if I need to do what is listed in #23 #26 #28

I (just) want to have each content profile node redirect to /user/...

What happens right now, that I dont like, is /content/username is accessible standalone.

YesCT’s picture

If this were an official submodule of content profile, I would feel much more comfortable using it, and I would feel like bugs in it would get more attention and get fixed.

roball’s picture

@ #14: Solution can be found at http://drupal.org/node/442004#comment-2607064

earthangelconsulting’s picture

re: #17... see this post: http://drupal.org/node/1077968