Not sure if anyone would think this to be useful but I know we would.

Forwarding a user profile is great but what would be great is if we could include fields of that profile we are sending. For example:

1. Profile username.
2. Profile photo.
3. Any other fields.

What happens now is that any of the user fields used are related to the current logged in user. Is this something of interest to the community in the future?

Comments

john.oltman’s picture

This would definitely be of interest. If you end up doing this, please ensure we don't lose the fields related to the logged in user. Just add new. On a related note, someone else mentioned Profile2 integration that might not be working. I assume you are referring to the old user profile that was deprecated in D7 but still part of core. Both are of interest.

glynster’s picture

Hi thanks for the response. More than anything I was just talking about entity fields. So when using the forward a non node page or even better still setup a case for user profiles we could use tokens to pull in those fields. It is a special case but I think it would be a great one. Perhaps a new template forward--profile.php.tpl. This way we could directly input the fields we wish in there and the template would know what to print based on the UID etc.

We currently are not using Profile2. We just use the fields in general associated with the profiles.

glynster’s picture

Where would I begin to setup the integration of tokens for this to work?

I mean the idea would be something like this:
[forward:user:field]
[forward:node:field]
[forward:taxonomy:field]

If we did it this way then whatever page is forwarded we can include these fields. Right now I can sent a user profile by using the print $content; . The issue here is it sends everything and I want to control what fields are sent. I thought for a moment we could use print ($user_profile['field_something']); but alas no luck.

To be honest if we can be able to customize the tpl for pull it whatever user profile fields this will be perfect for our needs. We would not use this module for anything other than user profiles.

Any help or guidance would be greatly appreciated.

glynster’s picture

OK for anyone who is interested in this feature here is what we did:

Added the following code to the top of the forward.php.tpl

<?php 
$path = drupal_get_normal_path($_GET["path"]);
$path = explode("/", $path);
$uid = $path[1];

$account = user_load($uid);
$profile_link = l($account->name, url("user/".$account->uid, array('absolute' => TRUE)));

 ?>

By doing this we were then able to pull in fields as needed but related to the link we were sharing

<?= $account->name ?>
<?= $account->field_profile_name["und"][0]["value"] ?>
<?= url("user/".$account->uid, array('absolute' => TRUE)) ?> (for links)

Worked a treat for us so hoping this can help for anyone else needing the same feature.

glynster’s picture

What do you think of my proposal at the end of the thread? This what we ended up implementing. I realize this is all related to the TPL but worked a treat for our needs.

nate covington’s picture

I'm trying to re-purpose the code from #4 to add node / CCK fields onto the forward.tpl.php template; having trouble. Here is the (mess of) code I've got:

<?php
$path = drupal_get_normal_path($_GET["path"]);
$path = explode("/", $path);
$nid = $path[1];
$forwardthumb = node_load($nid);
$img_uri = $forwardthumb->field_thumb['und'][0]['uri'];
$fid = $forwardthumb->field_thumb['und'][0]['fid'];
$thumbfilename = file_load($fid)->filename;
$derivative_uri = image_style_path($style, $image_uri);
$success = file_exists($derivative_uri) || image_style_create_derivative($style, $image_uri, $derivative_uri);
$new_image_url  = file_create_url($derivative_uri);
?>

In my testing, I've gotten the following text to output in my forwarded-email:
http://mysite.com/sites/default/files/styles/blog_thumb/public

(from the $new_image_url variable)

Which tells me that I've got it *partially* working, as it was able to indicate the correct folder / location... but I was never able to actually get it to spit out my image-file-name (e.g. thumbnail.png), just the path to the folder containing my image. Please let me know what I'm doing wrong?

Seems like part of this is a bit wonky, as it seems the $node variable in the template isn't the same $node variable used elsewhere in Drupal...?

Thanks!
-Nate

glynster’s picture

This is what we used to pull in a user photo:

<a href="<?= url("user/".$account->uid, array('absolute' => TRUE)) ?>"><?php $thumbnail = theme('image_style', array('style_name' => 'image_style', 'path' => $account->picture->uri)); echo $thumbnail; ?></a>

nate covington’s picture

glynster, it looks like part of your example code is missing? i took your code and this is what I tried, top of the forward.tpl.php file:

<?php
$path = drupal_get_normal_path($_GET["path"]);
$path = explode("/", $path);
$nid = $path[1];
$forwardthumb = node_load($nid);
?>

In the actual body of the email:

<?php
$thumbnail = theme('image_style', array('blog_thumb' => 'image_style', 'path' => $forwardthumb->thumb->uri)); 
echo $thumbnail;
?>

In testing, the email HTML spat this out:

<img typeof="foaf:Image" src="http://example.com/sites/default/files/styles//public?itok=KX3T-bKt" alt="" />

Seems like we're close...?

glynster’s picture

Hey there,

I forgot to wrap my example in code tags. Have a look above again and let me know if this works for you?

nate covington’s picture

No luck, I am going to post my working code here:
https://drupal.org/node/2107769

Had to hack forward.module file... the $nid variable wasn't passing through to forward.tpl using your code example, so I generated my image URL in forward.module and passed it along to forward.tpl

john.oltman’s picture

Version: 7.x-3.x-dev » 8.x-1.x-dev
Issue summary: View changes

This is fixed in 8.x branch - use hook_forward_token. See the forward.api.php file for more info.

deanflory’s picture

Not sure why the version was changed if it was already fixed for D8.

john.oltman’s picture

Version: 8.x-1.x-dev » 7.x-3.x-dev

I moved the version so anyone interested would know this has now been addressed in 8.x. But I see your point - if I have 7.x installed, and am looking for some code, I'd miss this if I had 7.x as a filter in my issue search. Moving back to original version.

john.oltman’s picture

Status: Active » Closed (outdated)