function galleria_field_formatter_view in Galleria 7
Implements hook_field_formatter_view().
Prepares a renderable array of images and adds the neccessary JS and CSS
File
- ./
galleria.module, line 549 - A light-weight, customizable image gallery plugin for Drupal based on jQuery
Code
function galleria_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
if ($field['type'] == 'media') {
$items = galleria_prepare_media_images($items);
}
elseif ($field['type'] == 'file') {
$items = galleria_prepare_file_images($items, $display['settings'], $langcode);
}
elseif ($field['type'] == 'node_reference') {
// Cleanup referenced_fields array
$referenced_fields =& $display['settings']['referenced_fields'];
foreach ($referenced_fields as &$field) {
$field = array_filter($field);
}
$referenced_fields = array_filter($referenced_fields);
// Collect items
$images = array();
foreach ($items as $item) {
$node = $item['node'];
foreach (field_info_instances('node', $node->type) as $field_name => $field_instance) {
$field_info = field_info_field($field_name);
if ($field_info['type'] == 'image' || $field_info['type'] == 'media') {
if (empty($referenced_fields) || !empty($referenced_fields[$node->type][$field_name])) {
$lang = field_language('node', $node, $field_name, $langcode);
$node_items = $node->{$field_name}[$lang];
if ($field_info['type'] == 'media') {
$node_items = galleria_prepare_media_images($node_items);
}
$images = array_merge($images, $node_items);
}
}
}
}
$items = $images;
}
$element = array();
if (count($items) > 0) {
$element[] = array(
'#theme' => 'galleria_container',
'#items' => $items,
'#settings' => $display['settings'],
);
}
return $element;
}