Mercurial > hg > rr-repo
diff sites/all/modules/flexslider/flexslider_fields/flexslider_fields.module @ 2:b74b41bb73f0
-- Google analytics module
author | danieleb <danielebarchiesi@me.com> |
---|---|
date | Thu, 22 Aug 2013 17:22:54 +0100 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sites/all/modules/flexslider/flexslider_fields/flexslider_fields.module Thu Aug 22 17:22:54 2013 +0100 @@ -0,0 +1,131 @@ +<?php + +/** + * @file + * Adds fields integration with FlexSlider + * + * @author jepedo + * @author Mathew Winstone <mwinstone@coldfrontlabs.ca> + */ + +/** + * Implements hook_field_formatter_info(). + * + * Adds the flexslider format option within the manage display form of + * of an image field. + */ +function flexslider_fields_field_formatter_info() { + return array( + 'flexslider' => array( + 'label' => t('flexslider'), + 'field types' => array('image', 'media'), + 'settings' => array( + 'optionset' => 'default', + 'caption' => FALSE, + ), + ), + ); +} + +/** + * Implements hook_field_formatter_settings_form(). + * + * Provides display settings form within the manage display page of + * an image field with formatter flexslider. + */ +function flexslider_fields_field_formatter_settings_form($field, $instance, $view_mode, $form, &$form_state) { + $display = $instance['display'][$view_mode]; + $settings = $display['settings']; + + $form = array(); + + // Show select box for the option set + $optionsets = array(); + ctools_include('export'); + foreach (flexslider_optionset_load_all() as $name => $optionset) { + $optionsets[$name] = check_plain($optionset->title); + } + + $form['optionset'] = array( + '#title' => t('Option set'), + '#type' => 'select', + '#options' => $optionsets, + '#default_value' => $settings['optionset'], + ); + + // If the image field doesn't have the Title field enabled, tell the user. + if ($instance['settings']['title_field'] == FALSE) { + $form['caption'] = array( + '#title' => t('Use image title as the caption'), + '#type' => 'checkbox', + '#disabled' => TRUE, + '#description' => t('You need to <a href="@url">enable the Title field</a> for this image field to be able use it as a caption.', array('@url' => url('admin/structure/types/manage/' . $instance['bundle'] . '/fields/' . $instance['field_name'], array('fragment' => 'edit-instance-settings-title-field', 'query' => array('destination' => 'admin/structure/types/manage/' . $instance['bundle'] . '/display'))))), + ); + } + else { + $form['caption'] = array( + '#title' => t('Use image title as the caption'), + '#type' => 'checkbox', + '#default_value' => $settings['caption'], + ); + } + + return $form; +} + +/** + * Implements hook_field_formatter_settings_summary(). + * + * Displays the summary of the set options of a flexslider formatted image field + */ +function flexslider_fields_field_formatter_settings_summary($field, $instance, $view_mode) { + $display = $instance['display'][$view_mode]; + $settings = $display['settings']; + + $summary = array(); + + // Load option set + ctools_include('export'); + if (!empty($settings['optionset'])) { + $o = flexslider_optionset_load($settings['optionset']); + if ($o !== NULL) { + $optionset = $o; + } + } + + // Build settings summary + $optionset = isset($optionset) ? $optionset->title : t('Default settings'); + $summary[] = t('Option set: %optionset', array('%optionset' => $optionset)); + + return implode('<br />', $summary); +} + +/** + * Implements hook_field_formatter_view(). + * + * Prepares a renderable array of images and adds the neccessary JS and CSS + */ +function flexslider_fields_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) { + if ($field['type'] == 'media') { + $image_items = array(); + foreach ($items as $item) { + if ($item['file']->type == 'image') { + $file = (array) $item['file']; + $file += array('alt' => '', 'title' => ''); + $image_items[] = $file; + } + } + $items = $image_items; + } + + $element = array(); + if (count($items) > 0) { + $element[] = array( + '#theme' => 'flexslider', + '#items' => $items, + '#settings' => $display['settings'], + ); + } + + return $element; +}