I am trying to make a members listing with ds and I am using profile 2. DO I go to Manage Display for PRofile 2, but I don't see any fields such as user picture, username, etc. Only profile fields such as about me. How can I create a member's listing?

Comments

pfrenssen’s picture

You have to create your own custom Display Suite fields. For an example that uses a profile picture field from the Profile2 module see #1293410: Using an image field from the Profile2 module in Display Suite.

Here is an example of a custom field that concatenates two fields (first name and last name) from a Profile2 profile to form a "full name" field:

/**
 * Implements hook_ds_fields_info().
 */
function MODULENAME_ds_fields_info($entity_type) {
  $fields = array();

  $fields['userlist_fullname'] = array(
    'title' => t('Full name'),
    'field_type' => DS_FIELD_TYPE_FUNCTION,
    'function' => '_MODULENAME_ds_field_user_full_name',
  );

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

/**
 * Custom field displaying the full name of a user, linked to the user profile.
 */
function _MODULENAME_ds_field_user_full_name($field) {
  if (isset($field['entity_type']) && $field['entity_type'] == 'user' && $profile = profile2_load_by_user($field['entity'])) {
    $first_name = field_get_items('profile2', $profile['personal_information'], 'field_info_first_name');
    $last_name = field_get_items('profile2', $profile['personal_information'], 'field_info_last_name');

    $full_name = !empty($first_name[0]['value']) ? $first_name[0]['value'] : '';
    $full_name .= !empty($last_name[0]['value']) ? ' ' . $last_name[0]['value'] : '';

    return l($full_name, 'user/' . $field['entity']->uid);
  }
  return FALSE;
}
hedley’s picture

Status: Active » Fixed

Here is an example of a custom field just for nodes

/**
 * Implements hook_ds_fields_info().
 */
function MODULENAME_ds_fields_info($entity_type) {

  // Provide a custom field to display suite

  $fields = array();

  $fields['node']['field_name'] = array(
    'title' => t('Field Name'),
    'field_type' => DS_FIELD_TYPE_FUNCTION,
    'function' => 'MODULENAME_ds_field_field_name',
  );

  return $fields;
}

/**
 * Custom field stuff
 */
function MODULENAME_ds_field_field_name($field) {
   // Custom stuff goes here
    return 'My custom stuff';
}

Status: Fixed » Closed (fixed)

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