You are here

function theme_semantic_field in Semantic Fields 7

Theme the fields

1 string reference to 'theme_semantic_field'
semantic_fields_theme_registry_alter in ./semantic_fields.module
Implements hook_theme_registry_alter().

File

./semantic_fields.module, line 357
The functionality of the module

Code

function theme_semantic_field(&$variables) {
  $output = '';

  // Token support for nodes
  if (module_exists('token') == TRUE) {
    global $user;
    if (arg(0) == 'node') {
      $nid = arg(1);
    }
    if (isset($nid)) {
      $node = node_load($nid);
      $data = array(
        'node' => $node,
        'user' => $user,
      );
    }
  }

  // Render the label, if it's not hidden.
  $variables['label_element'] = trim($variables['label_element']);
  if (!$variables['label_hidden']) {
    if (!empty($variables['label_element'])) {
      $output .= '<' . $variables['label_element'] . ' class="' . $variables['label_classes'] . '"' . $variables['title_attributes'] . '>';
    }
    $output .= $variables['label'] . $variables['label_suffix'] . '&nbsp;';
    if (!empty($variables['label_element'])) {
      $output .= '</' . $variables['label_element'] . '>';
    }
  }

  // Render the items.
  if (!empty($variables['content_element'])) {
    $output .= '<' . $variables['content_element'] . ' class="' . $variables['content_classes'] . '"' . $variables['content_attributes'] . '>';
  }
  foreach ($variables['items'] as $delta => $item) {
    if ($variables['item_element']) {
      $output .= '<' . $variables['item_element'] . ' class="' . $variables['item_classes'][$delta] . '"' . $variables['item_attributes'][$delta] . '>';
    }
    $output .= drupal_render($item);
    if ($variables['item_element']) {
      $output .= '</' . $variables['item_element'] . '>';
    }
    if (!empty($variables['item_separator']) && $delta < count($variables['items']) - 1) {
      $output .= $variables['item_separator'];
    }
  }
  if (!empty($variables['content_element'])) {
    $output .= '</' . $variables['content_element'] . '>';
  }

  // Render the top-level DIV.
  if (!empty($variables['field_element'])) {
    $output = '<' . $variables['field_element'] . ' class="' . $variables['classes'] . '"' . $variables['attributes'] . '>' . $output . '</' . $variables['field_element'] . '>';
  }

  // Add a prefix and suffix to the field, if specified
  if (!empty($variables['field_prefix'])) {
    $output = $variables['field_prefix'] . $output;
  }
  if (!empty($variables['field_suffix'])) {
    $output .= $variables['field_suffix'];
  }
  if (isset($nid)) {
    return token_replace($output, $data);
  }
  else {
    return $output;
  }
}