Hi, I have the following:

display suite
Drupal 7
panels
views
cck
Profile2
Entity API

well, I created a custom node type, then I created a view to recover that node using views and display suite.

On the other hand, I created a profile with Profile2 with custom fields, one of them a photo.

What is the best way to recover the author's profile node photo field (profile2) on display suite?

using a dynamic field there is no code section profile/profile2, and using code field tokens I can see all profile fields except the image field... [profile2:field-face]

thanks, greetings

Comments

pfrenssen’s picture

Assigned: pepejose » Unassigned
Priority: Major » Normal
Status: Active » Fixed

You can make a custom DS field for this. Something like this:

/**
 * Implements hook_ds_fields_info().
 */
function MODULENAME_ds_fields_info($entity_type) {
  // Compile a list of image styles for the profile picture options.
  $picture_formatters = array();
  foreach (image_styles() as $formatter) {
    $picture_formatters['MODULENAME_picture_' . $formatter['name']] = drupal_ucfirst(str_replace('_', ' ', $formatter['name']));
  }

  $fields = array();
  $fields['userlist_picture'] = array(
    'title' => t('Profile picture'),
    'field_type' => DS_FIELD_TYPE_FUNCTION,
    'function' => '_MODULENAME_ds_field_userlist_picture',
    'properties' => array(
      'formatters' => $picture_formatters,
    ),
  );

  return array('user' => $fields);
}

/**
 * Custom field displaying a user's profile picture.
 */
function _MODULENAME_ds_field_userlist_picture($field) {
  if (isset($field['entity_type']) && $field['entity_type'] == 'user' && ($profile = profile2_load_by_user($field['entity']))) {
    if ($picture = field_get_items('profile2', $profile['personal_information'], 'field_personal_info_image')) {
      $picture = reset($picture);
    }

    // Provide a default picture for users that have not yet uploaded one.
    if (!isset($picture['uri']) || empty($picture['uri'])) {
      $picture['uri'] = 'public://profile_pictures/profile_default.png';
      $picture['width'] = 247;
      $picture['height'] = 247;
    }

    // Retrieve the user's first name to use in the alt tag.
    $first_name = field_get_items('profile2', $profile['personal_information'], 'field_personal_info_first_name');
    $first_name = !empty($first_name[0]['safe_value']) ? $first_name[0]['safe_value'] : t('User');

    $vars = array(
      'style_name' => str_replace('MODULENAME_picture_', '', $field['formatter']),
      'path' => $picture['uri'],
      'width' => $picture['width'],
      'height' => $picture['height'],
      'alt' => t('@user\'s picture', array('@user' => $first_name)),
    );

    $image = theme('image_style', $vars);

    return l($image, 'user/' . $field['entity']->uid, array('html' => TRUE));
  }
  return FALSE;
}
pfrenssen’s picture

Title: help with display suite and extra information » Using an image field from the Profile2 module in Display Suite

Updating title.

Status: Fixed » Closed (fixed)

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