You are here

function theme_custom_formatters_formatter in Custom Formatters 6

1 string reference to 'theme_custom_formatters_formatter'
custom_formatters_theme in ./custom_formatters.module
Implements hook_theme().
3 theme calls to theme_custom_formatters_formatter()
theme_custom_formatters_content_multigroup in includes/content_multigroup.inc
theme_custom_formatters_fieldgroup in includes/fieldgroup.inc
theme_custom_formatters_preview in ./custom_formatters.admin.inc

File

./custom_formatters.module, line 395
Contains core functions for the Custom Formatters module.

Code

function theme_custom_formatters_formatter($element) {
  global $theme_path, $theme_info, $conf;
  $output = '';

  // Store current theme path.
  $old_theme_path = $theme_path;

  // Restore theme_path to the theme, as long as drupal_eval() executes,
  // so code evaluted will not see the caller module as the current theme.
  // If theme info is not initialized get the path from theme_default.
  $theme_path = !isset($theme_info) ? drupal_get_path('theme', $conf['theme_default']) : dirname($theme_info->filename);

  // Give modules a chance to alter the formatter element.
  drupal_alter('custom_formatters_formatter_element', $element);
  $info = _content_type_info();
  $field = $element['#devel'] ? array(
    'module' => $element['#field_type'],
  ) : $info['fields'][$element['#field_name']];
  $formatter = is_object($element['#formatter']) ? $element['#formatter'] : custom_formatters_formatter($element['#formatter']);

  // Build array of items.
  $items = isset($element['#item']) ? array(
    &$element['#item'],
  ) : array();
  if (!$items) {
    foreach (element_children($element) as $delta) {
      $items[$delta] =& $element[$delta]['#item'];
    }
  }

  // Sanitize items.
  if (function_exists($function = "{$field['module']}_field")) {
    $function('sanitize', $element['#node'], $field, $items, FALSE, FALSE);
  }

  // Process formatter if field is not empty.
  $function = "{$field['module']}_content_is_empty";
  if (function_exists($function) && !$function($items[0], $field) || !function_exists($function) || $element['#devel']) {
    switch ($formatter->mode) {
      case 'basic':
        $output = _custom_formatters_token_replace($formatter, $element);
        break;
      case 'advanced':
        ob_start();
        print eval($formatter->code);
        $output = ob_get_contents();
        ob_end_clean();
        break;
    }
  }

  // Recover original theme path.
  $theme_path = $old_theme_path;
  return $output;
}