function lightbox2_filefield_formatter in Lightbox2 5.2
Function to display a filefield file in a lightbox.
Parameters
$field: The field the action is being performed on.
$item: An array, keyed by column, of the data stored for this item in this field.
$formatter: The formatter to use for the field.
$node: The node object.
1 call to lightbox2_filefield_formatter()
- lightbox2_field_formatter in ./
lightbox2.module - Implementation of hook_field_formatter().
File
- ./
lightbox2.module, line 2225 - Enables the use of lightbox2 which places images above your current page, not within. This frees you from the constraints of the layout, particularly column widths.
Code
function lightbox2_filefield_formatter($field, $item, $formatter, $node) {
if (user_access('view filefield uploads') && is_array($item) && is_file($item['filepath']) && $item['list']) {
drupal_add_css(drupal_get_path('module', 'filefield') . '/filefield.css');
$path = $item['fid'] == 'upload' ? file_create_filename($item['filename'], file_create_path($field['widget']['file_path'])) : $item['filepath'];
$icon = theme('filefield_icon', $item);
$description = $item['description'];
if (empty($description)) {
$description = $item['filename'];
}
$node_link = '';
if (!empty($node_link_text) && !empty($link)) {
$target = variable_get('lightbox2_node_link_target', FALSE);
if (!empty($target)) {
$attributes = array(
'target' => $target,
);
}
$node_link_text = variable_get('lightbox2_node_link_text', 'View Image Details');
if (!empty($node_link_text)) {
$node_link .= '<br /><br />' . l($node_link_text, $link, $attributes);
}
}
$link_attributes = array();
$ext = array_pop(explode('.', $item['filename']));
if (lightbox2_supported_file_extension($ext)) {
$link_attributes = array(
'rel' => 'lightframe[][' . $description . $node_link . ']',
);
}
$url = file_create_url($path);
return '<div class="filefield-item">' . $icon . l($description, $url, $link_attributes) . '</div>';
}
return '';
}