function field_orbit_field_formatter_view in ZURB Orbit 7.2
Same name and namespace in other branches
- 7 field_orbit.module \field_orbit_field_formatter_view()
Implements hook_field_formatter_view().
File
- ./
field_orbit.module, line 402 - Implement a orbit formatter for fields.
Code
function field_orbit_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
$settings = $display['settings'];
if (module_exists('field_multiple_limit') && isset($settings['field_multiple_limit']) && $settings['field_multiple_limit'] != FIELD_MULTIPLE_LIMIT_ALL) {
$items = array_slice($items, 0, $settings['field_multiple_limit']);
}
$element = array();
// Get the correct caption and set title and alt text
// We only caption images - and in Media 2.x it applies a Title and Alt field for us.
if ($settings['orbit_caption'] != '') {
foreach ($items as $delta => $item) {
if ($field['type'] == 'file' || $field['type'] == 'image') {
$wrapper = entity_metadata_wrapper('file', $items[$delta]['fid']);
if (isset($wrapper->{$settings['orbit_caption']})) {
$items[$delta]['caption'] = $wrapper->{$settings['orbit_caption']}
->value();
$items[$delta]['alt'] = $wrapper->{$settings['orbit_caption']}
->value();
}
}
}
}
$links = array(
'orbit_link' => $settings['orbit_link'],
'orbit_caption_link' => 'caption_path',
);
$content_uri = entity_uri($entity_type, $entity);
// Get the correct field for identifying entity (used to get correct links)
$entity_info = entity_get_info($entity_type);
$entity_id_field = $entity_info['entity keys']['id'];
// Loop through required links (because image and caption can have different links).
foreach ($links as $setting => $path) {
// Check if the formatter involves a link.
$link_type = '';
if ($field['type'] == 'file' && drupal_substr($settings[$setting], 0, 6) == 'field_') {
$infos = field_info_field($settings[$setting]);
$link_type = $infos['type'];
}
// Generate special links (other than node)
foreach ($items as $delta => $item) {
switch ($link_type) {
case 'link_field':
if ($field['type'] == 'file') {
if (isset($items[$delta][$path]) && !empty($items[$delta][$path][LANGUAGE_NONE][0]['url'])) {
$external_url = url_is_external($items[$delta][$path][LANGUAGE_NONE][0]['url']);
$items[$delta]['slide_link'] = array(
'path' => $items[$delta][$path][LANGUAGE_NONE][0]['url'],
'external' => $external_url,
'options' => array(
'attributes' => array(
'target' => $external_url ? '_blank' : '_self',
),
),
);
}
}
break;
}
}
}
if (count($items)) {
$element[] = array(
'#theme' => 'field_orbit',
'#items' => $items,
'#options' => array(
'animation' => $settings['animation'],
'timer_speed' => $settings['timer_speed'],
'pause_on_hover' => $settings['pause_on_hover'],
'resume_on_mouseout' => $settings['resume_on_mouseout'],
'animation_speed' => $settings['animation_speed'],
'stack_on_small' => $settings['stack_on_small'],
'navigation_arrows' => $settings['navigation_arrows'],
'slide_number' => $settings['slide_number'],
'container_class' => $settings['container_class'],
'stack_on_small_class' => $settings['stack_on_small_class'],
'next_class' => $settings['next_class'],
'prev_class' => $settings['prev_class'],
'bullets' => $settings['bullets'],
'bulletThumbs' => $settings['bulletThumbs'],
'timer_container_class' => $settings['timer_container_class'],
'timer_paused_class' => $settings['timer_paused_class'],
'timer_progress_class' => $settings['timer_progress_class'],
'slides_container_class' => $settings['slides_container_class'],
'bullets_container_class' => $settings['bullets_container_class'],
'bullets_active_class' => $settings['bullets_active_class'],
'slide_number_class' => $settings['slide_number_class'],
'caption_class' => $settings['caption_class'],
'active_slide_class' => $settings['active_slide_class'],
'orbit_transition_class' => $settings['orbit_transition_class'],
'timer' => $settings['timer'],
'variable_height' => $settings['variable_height'],
'orbit_image_style' => $settings['orbit_image_style'],
'orbit_title' => $settings['orbit_title'],
'orbit_caption' => $settings['orbit_caption'],
'orbit_link' => $settings['orbit_link'],
'orbit_bullet_thumbs' => $settings['orbit_bullet_thumbs'],
),
'#entity' => $entity,
);
}
return $element;
}