You are here

function content_profile_realname_get_fields in Real Name 6

File

./realname_content_profile.inc, line 64
Realname module support for Content Profile module.

Code

function content_profile_realname_get_fields($current, $type) {
  $fields = $links = array();
  $all_fields = content_fields(NULL, $type);
  if ($all_fields) {
    foreach ($all_fields as $field_name => $field_attributes) {

      // If it's not they type we are looking for, then skip the field.
      if ($field_attributes['type_name'] != $type) {
        continue;
      }
      switch ($field_attributes['type']) {
        case 'text':
          if ($field_attributes['multiple']) {
            drupal_set_message(t('The RealName module does not currently support fields with multiple values, such as @fld.', array(
              '@fld' => $field_name,
            )), 'warning');
          }
          else {
            $selected = array_key_exists($field_name, $current);
            $fields[$field_name] = array(
              'title' => $field_attributes['widget']['label'],
              'weight' => $selected ? $current[$field_name] : 0,
              'selected' => $selected,
            );
          }
          break;
        case 'link':
          $links[$field_name] = $field_attributes['widget']['label'];
      }
    }
  }
  else {
    drupal_set_message(t('The !type content type has no fields to use.', array(
      '!type' => $type,
    )), 'error');
  }
  if (variable_get('realname_use_title', FALSE)) {
    $fields['title'] = array(
      'title' => t('Node title'),
      'weight' => isset($current['title']) ? $current['title']['weight'] : 0,
      'selected' => array_key_exists('title', $current),
    );
  }
  return array(
    'fields' => $fields,
    'links' => $links,
  );
}