function url_field_formatter_view in URL field 8
Same name and namespace in other branches
- 7 url.module \url_field_formatter_view()
Implements hook_field_formatter_view().
File
- ./
url.module, line 291 - Provides a URL field type that stores external links with optional titles.
Code
function url_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
$element = array();
$intance_settings = $instance['settings'];
$settings = $display['settings'];
foreach ($items as $delta => $item) {
// By default use the full URL as the link title.
$link_title = $item['value'];
// If the title field value is available, use it for the link title.
if (!empty($item['title'])) {
// Unsanitizied token replacement here because $options['HTML'] is FALSE
// by default in theme_link().
$link_title = token_replace($item['title'], array(
$entity_type => $entity,
), array(
'sanitize' => FALSE,
'clear' => TRUE,
));
}
// Trim the link title to the desired length.
if (!empty($settings['trim_length'])) {
$link_title = truncate_utf8($link_title, $settings['trim_length'], FALSE, TRUE);
}
$element[$delta] = array(
'#type' => 'link',
'#title' => $link_title,
'#href' => $item['path'],
'#options' => $item['options'],
);
}
return $element;
}