You are here

function ds_render_field in Display Suite 7.2

Same name and namespace in other branches
  1. 7 ds.module \ds_render_field()

Render a field.

1 string reference to 'ds_render_field'
ds_ds_fields_info in ./ds.ds_fields_info.inc
Implements hook_ds_fields_info().

File

./ds.module, line 977
Display Suite core functions.

Code

function ds_render_field($field) {
  $title_field = FALSE;
  $output = '';
  $settings = isset($field['formatter_settings']) ? $field['formatter_settings'] : array();
  $settings += $field['properties']['default'];

  // Basic string.
  if (isset($settings['link text'])) {
    $output = t($settings['link text']);
  }
  elseif (isset($field['properties']['entity_render_key']) && isset($field['entity']->{$field['properties']['entity_render_key']})) {
    if ($field['entity_type'] == 'user' && $field['properties']['entity_render_key'] == 'name') {
      $output = format_username($field['entity']);
    }
    else {
      $title_field = $field['properties']['entity_render_key'] == 'title' && $field['entity_type'] == 'node';
      $output = $field['entity']->{$field['properties']['entity_render_key']};
    }
  }
  if (empty($output)) {
    return;
  }

  // Link.
  if ($settings['link']) {
    if (isset($field['entity']->uri)) {
      $uri_info = $field['entity']->uri;
    }
    else {
      $uri_info = entity_uri($field['entity_type'], $field['entity']);
    }
    if (isset($settings['link class'])) {
      $uri_info['options']['attributes']['class'][] = $settings['link class'];
    }
    $output = l($output, $uri_info['path'], $uri_info['options']);
    if ($title_field) {
      $output = ds_edit_support('title', $output, $field);
    }
  }
  else {
    $output = check_plain($output);
    if ($title_field) {
      $output = ds_edit_support('title', $output, $field);
    }
  }

  // Wrapper and class.
  if (!empty($settings['wrapper'])) {
    $wrapper = check_plain($settings['wrapper']);
    $class = !empty($settings['class']) ? ' class="' . check_plain($settings['class']) . '"' : '';
    $output = '<' . $wrapper . $class . '>' . $output . '</' . $wrapper . '>';
  }
  return $output;
}