comparison 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
comparison
equal deleted inserted replaced
1:67ce89da90df 2:b74b41bb73f0
1 <?php
2
3 /**
4 * @file
5 * Adds fields integration with FlexSlider
6 *
7 * @author jepedo
8 * @author Mathew Winstone <mwinstone@coldfrontlabs.ca>
9 */
10
11 /**
12 * Implements hook_field_formatter_info().
13 *
14 * Adds the flexslider format option within the manage display form of
15 * of an image field.
16 */
17 function flexslider_fields_field_formatter_info() {
18 return array(
19 'flexslider' => array(
20 'label' => t('flexslider'),
21 'field types' => array('image', 'media'),
22 'settings' => array(
23 'optionset' => 'default',
24 'caption' => FALSE,
25 ),
26 ),
27 );
28 }
29
30 /**
31 * Implements hook_field_formatter_settings_form().
32 *
33 * Provides display settings form within the manage display page of
34 * an image field with formatter flexslider.
35 */
36 function flexslider_fields_field_formatter_settings_form($field, $instance, $view_mode, $form, &$form_state) {
37 $display = $instance['display'][$view_mode];
38 $settings = $display['settings'];
39
40 $form = array();
41
42 // Show select box for the option set
43 $optionsets = array();
44 ctools_include('export');
45 foreach (flexslider_optionset_load_all() as $name => $optionset) {
46 $optionsets[$name] = check_plain($optionset->title);
47 }
48
49 $form['optionset'] = array(
50 '#title' => t('Option set'),
51 '#type' => 'select',
52 '#options' => $optionsets,
53 '#default_value' => $settings['optionset'],
54 );
55
56 // If the image field doesn't have the Title field enabled, tell the user.
57 if ($instance['settings']['title_field'] == FALSE) {
58 $form['caption'] = array(
59 '#title' => t('Use image title as the caption'),
60 '#type' => 'checkbox',
61 '#disabled' => TRUE,
62 '#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'))))),
63 );
64 }
65 else {
66 $form['caption'] = array(
67 '#title' => t('Use image title as the caption'),
68 '#type' => 'checkbox',
69 '#default_value' => $settings['caption'],
70 );
71 }
72
73 return $form;
74 }
75
76 /**
77 * Implements hook_field_formatter_settings_summary().
78 *
79 * Displays the summary of the set options of a flexslider formatted image field
80 */
81 function flexslider_fields_field_formatter_settings_summary($field, $instance, $view_mode) {
82 $display = $instance['display'][$view_mode];
83 $settings = $display['settings'];
84
85 $summary = array();
86
87 // Load option set
88 ctools_include('export');
89 if (!empty($settings['optionset'])) {
90 $o = flexslider_optionset_load($settings['optionset']);
91 if ($o !== NULL) {
92 $optionset = $o;
93 }
94 }
95
96 // Build settings summary
97 $optionset = isset($optionset) ? $optionset->title : t('Default settings');
98 $summary[] = t('Option set: %optionset', array('%optionset' => $optionset));
99
100 return implode('<br />', $summary);
101 }
102
103 /**
104 * Implements hook_field_formatter_view().
105 *
106 * Prepares a renderable array of images and adds the neccessary JS and CSS
107 */
108 function flexslider_fields_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
109 if ($field['type'] == 'media') {
110 $image_items = array();
111 foreach ($items as $item) {
112 if ($item['file']->type == 'image') {
113 $file = (array) $item['file'];
114 $file += array('alt' => '', 'title' => '');
115 $image_items[] = $file;
116 }
117 }
118 $items = $image_items;
119 }
120
121 $element = array();
122 if (count($items) > 0) {
123 $element[] = array(
124 '#theme' => 'flexslider',
125 '#items' => $items,
126 '#settings' => $display['settings'],
127 );
128 }
129
130 return $element;
131 }