Hii, first of all sorry for my bad lang :D
After reading almost all documentation about this module but I still confused :(.
Actually only like this my problem,
1. I create some field for user using profile2 module, like ID number and others, And I only need to display ID Number that I created to author pane. Please help me how to solve it.
2. I need to display user city and province from Location Module to author pane too, How to do this

Let me add what I need with attach image below

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Michelle’s picture

Priority: Major » Normal
Status: Needs work » Active

The Author Pane end of this is fairly simple and also well documented. Where the difficulty lies is figuring out how to get the data you need from those other modules. This isn't something I know off the top of my head to tell you. You can try asking in the queues of those modules or in the forum. I'll leave this active for a while in case someone else wants to take the time to dig into this for you but it isn't something I can help you with.

Michelle

jay.lee.bio’s picture

Issue summary: View changes

Eboss, I'm trying to do the same exact thing and just found some related code at https://www.drupal.org/node/1360258, #7. I'll report back if I figure something out.

jay.lee.bio’s picture

Man I got so close, but no cigar. I got the following simple field to show up:

<?php
$account = user_load($user->uid);
$profile = profile2_load_by_user($account, 'profile');
print $profile->field_user_first_name['und']['0']['value'];
?>

But the following is what we want that doesn't work:

<?php
$account = user_load($user->uid);
$profile = profile2_load_by_user($account, 'profile');
print $profile->field_user_location['und']['0']['value'];
?>

If anyone knows what I'm doing wrong, let me know. Thanks!

Michelle’s picture

I suggest getting either devel or a debugger and seeing what is in $profile at that point. The path to the value might not be the same for that field as for the other. Alternately, get the Entity module and use this technique.

System Lord’s picture

I got this code to display location (city and state), but I'm still getting the error below.

if (!empty($account)):
$profile = profile2_load_by_user($account,NULL);  
print drupal_render(field_view_field('profile2', $profile['profile_name'], 'field_kld_myage', 'value')); 
print drupal_render(field_view_field('profile2', $profile['profile_name'], 'field_stnrd_location', 'value')); 
print render($user_profile); 
endif;

ERROR

Strict warning: Only variables should be passed by reference in include() (line 78 of /home/site/public_html/site2/sites/all/themes/sky/templates/author-pane.tpl.php).
Strict warning: Only variables should be passed by reference in include() (line 79 of /home/site/public_html/site2/sites/all/themes/sky/templates/author-pane.tpl.php).

My hope is someone will see this and have the "ah-ha" moment I've been waiting for and explain how I can fix this.

These are lines 78 and 79:

print drupal_render(field_view_field('profile2', $profile['profile_name'], 'field_kld_myage', 'value'));
print drupal_render(field_view_field('profile2', $profile['profile_name'], 'field_stnrd_location', 'value'));

System Lord’s picture

FileSize
4.76 KB

I also do not need the labels displayed. Any ideas how to not show them? See image.

jay.lee.bio’s picture

System Lord, I had a similar issue regarding #5 after upgrading to PHP 7.0.2 and the following link helped me solve my problem (look at the answer by saru1683): https://www.digitalocean.com/community/questions/strict-warning-only-var...

So try something like this:

$render_age = drupal_render(field_view_field('profile2', $profile['profile_name'], 'field_kld_myage', 'value'));
print $render_age;
$render_location = drupal_render(field_view_field('profile2', $profile['profile_name'], 'field_stnrd_location', 'value'));
print $render_location;

And for #6, a temporary solution might be to just use CSS to hide the labels:

.label_age, .label_location { display: none; }

P.S. If your solution solves my problem at #3 (I'm quite tied up at the moment), I'll provide an update accordingly.

jay.lee.bio’s picture

System Lord, I actually got everything working on my website! :D

1) Ignore my incorrect code at #7. Use the following version instead:

$render_age = field_view_field('profile2', $profile['profile_name'], 'field_kld_myage', 'value');
print drupal_render($render_age);
$render_location = field_view_field('profile2', $profile['profile_name'], 'field_stnrd_location', 'value');
print drupal_render($render_location);

2) In my case using your code, I got errors when I went to other users' profile pages that didn't have their location fields filled in. So after playing around with and mashing up both #3 & #5, I came up with the following that seems to work 100%:

<?php
$user = user_load(arg(1));
$account = user_load($user->uid);
$profile = profile2_load_by_user($account, NULL);
if (!empty($profile)):
  $render_user_location = field_view_field('profile2', $profile['profile'], 'field_user_location', 'value');
  print drupal_render($render_user_location);
endif;
?>

3) I was right about using CSS to hide the labels.

System Lord’s picture

Thank you for the quick response. I did this and still get the same results and error.

        <?php $profile = profile2_load_by_user($account,NULL); ?>
          <div  class="author-pane-line author-pane-profile2">   
            <?php $render_age = drupal_render(field_view_field('profile2', $profile['profile_name'], 'field_kld_myage', 'value')); ?>
            <?php print $render_age; ?>
            <?php $render_location = drupal_render(field_view_field('profile2', $profile['profile_name'], 'field_stnrd_location', 'value')); ?>
            <?php print $render_location; ?>
          </div>

I don't know php well, but I can understand what saru1683 is pointing out. I just don't know how to make it work.

System Lord’s picture

I just seen your #8. Let me try

jay.lee.bio’s picture

Well, you sure did a hell of a good job on #5 for someone who doesn't know PHP well. :P

I took a quick look at #9 and noticed that it's actually using #7 (it looks like we both posted almost at the same time). Make sure to use #8 and let me know if it still doesn't take care of your issues. :)

System Lord’s picture

Nice! #8(2) worked! No errors!

I also did this to include both "age" and "city" but is it the correct way?

<?php $user = user_load(arg(1)); ?>
<?php $account = user_load($user->uid); ?>
<?php $profile = profile2_load_by_user($account, NULL); ?>
<?php if (!empty($profile)): ?>
<?php $render_profile = field_view_field('profile2', $profile['profile_name'], 'field_stnrd_location', 'value'); ?>
<?php print drupal_render($render_profile); ?>
<?php endif; ?>
<?php if (!empty($profile)): ?>
<?php $render_profile = field_view_field('profile2', $profile['profile_name'], 'field_kld_myage', 'value'); ?>
<?php print drupal_render($render_profile); ?>
<?php endif; ?>
jay.lee.bio’s picture

Hmmm, #12 looks confusing. The last part also looks like it's writing over itself so that the age will show up but not the location. I'm not the best developer myself, but I think the following will work better:

<?php
$user = user_load(arg(1));
$account = user_load($user->uid);
$profile = profile2_load_by_user($account, NULL);
if (!empty($profile)):
$render_location = field_view_field('profile2', $profile['profile_name'], 'field_stnrd_location', 'value');
print drupal_render($render_location);
$render_myage = field_view_field('profile2', $profile['profile_name'], 'field_kld_myage', 'value');
print drupal_render($render_myage);
endif;
?>
System Lord’s picture

#13 works great! Thank you, wwwjaylee for all your help!

jay.lee.bio’s picture

No no no, thank you for getting the toughest part working. I just got lucky finishing it up, and I'm still surprised it actually works. :D

System Lord’s picture

Let's leave this open for others to review. I'm glad it works, but I still wonder if it's the best way. The three loads seems excessive "User, Account, Profile". I don't really know, tho. Just looks odd.

System Lord’s picture

FileSize
5.41 KB

Here's what I finally did with it and it's exactly what I wanted. And, it's all in author_pane.tpl.php. No custom block or custom View.

jay.lee.bio’s picture

Category: Support request » Feature request
Status: Active » Needs review

Per #16, I'm changing the status to "Needs review". I'm also changing it to "Feature request", since that's what it looks to me.

Michelle’s picture

Category: Feature request » Support request
Status: Needs review » Fixed

This is a support request from almost 4 years ago. It's great that other people are getting help from it but I don't see how this is a feature request since and it doesn't need review because there's no patch nor code that's even close to something that could be added to the module. If someone wants to make a patch for location and/or profile2 integration they should go in separate issues. Also keep in mind that they would need to be proper integrations, not code shoved in the template. Also, I'm hesitant to add more integrations at this point as they are difficult to maintain and keep in sync with the integrated modules. Location, in fact, was removed due to a security issue years ago because they changed something on their end. At this point, I'd rather see it end up as a documentation page than hardcode the integration into the module itself.

jay.lee.bio’s picture

Michelle, fair enough. But do you have a link to the security issue regarding Location? Its home page seems fine to me at the moment.

Michelle’s picture

As I said, it was years ago. And it wasn't a security release of Location; it was a security release of AP due to Location changing something on their end and causing the integration to be insecure. This was an ongoing frustration for me for many years because I never intended these integrations be hosted in AP itself but ended up having to because I couldn't get cooperation from the other module authors. https://www.drupal.org/node/1271388

System Lord’s picture

I can successfully use this..

$uid = user_load($account->uid);
$profile = profile2_load_by_user($account, NULL);

instead of this...

$user = user_load(arg(1));
$account = user_load($user->uid);
$profile = profile2_load_by_user($account, NULL);
jay.lee.bio’s picture

With #22, can you try going to other users' profile pages that did NOT have their location fields filled in and see if it still works? Also, does $uid eventually get used somewhere? It looks like it's just sitting there doing nothing right now.

System Lord’s picture

Hmm. Well, I just removed that line $user = user_load(arg(1)); and it still works. So, even better!

I won't have any users without their location filled in. I use "complete profile" which forces my users to complete the location fields before their account can be created.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.