function title_field_formatter_view in Title 7
Implements hook_field_formatter_view().
File
- ./
title.field.inc, line 129 - Implement a title field formater.
Code
function title_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
$settings = $display['settings'];
$output = '';
if (isset($items[0]['safe_value'])) {
$output = $items[0]['safe_value'];
}
elseif (isset($items[0]['value'])) {
$output = _text_sanitize($instance, $langcode, $items[0], 'value');
}
$element = array();
if (!empty($output)) {
if (in_array($settings['title_link'], array(
'content',
'content_absolute',
))) {
$uri = entity_uri($entity_type, $entity);
// If trimmed is enabled.
if (!empty($settings['enable_trim'])) {
$trimmed_output = text_summary($output, $instance['settings']['text_processing'] ? $items[0]['format'] : NULL, $display['settings']['trim_length']);
// If we performed trimmed, add ellipsis in the end.
if (drupal_strlen($output) != drupal_strlen($trimmed_output)) {
$output = $trimmed_output . '…';
}
}
$options = array(
'html' => TRUE,
'absolute' => $settings['title_link'] === 'content_absolute',
);
if (!empty($uri['options'])) {
$options = array_merge($options, $uri['options']);
}
$output = l($output, $uri['path'], $options);
}
$wrap_tag = empty($settings['title_style']) ? '_none' : $settings['title_style'];
if ($wrap_tag != '_none') {
$variables = array(
'element' => array(
'#tag' => $wrap_tag,
'#value' => $output,
),
);
if (!empty($settings['title_class'])) {
$variables['element']['#attributes'] = array(
'class' => $settings['title_class'],
);
}
$output = theme('html_tag', $variables);
}
$element = array(
array(
'#markup' => $output,
),
);
}
return $element;
}