Permalink
Find file
Fetching contributors…
Cannot retrieve contributors at this time
133 lines (115 sloc) 3.48 KB
<?php
/**
* This module will allow fields to be formatter in a particular way using
* jquery carousel formattrer.
*/
/**
* Implements hook_field_formatter_info().
*/
function jcformatter_field_formatter_info() {
return array(
'jc_gallery_simple' => array(
'label' => t('Simple Gallery formatter'),
'field types' => array('image'),
'settings' => array(
'pic_size' => 'thumbnail',
),
),
);
}
/**
* Implementing hook_theme()
*/
function jcformatter_theme() {
return array(
'jc_gallery' => array(
'variables' => array('data' => NULL),
'template' => 'template/jc_gallery',
),
);
}
/**
* Implements hook_menu().
*/
function jcformatter_menu() {
$items['admin/config/media/jcformatter'] = array(
'title' => 'JC Formtter settings',
'description' => 'Configure the settings for JC formatter.',
'page callback' => 'drupal_get_form',
'page arguments' => array('jcformatter_settings_form'),
'access arguments' => array('administer site configuration'),
'file' => 'jcformatter.admin.inc',
);
$items['admin/config/media/jcformatter/config'] = array(
'title' => 'JC Formtter settings',
'page callback' => 'drupal_get_form',
'page arguments' => array('jcformatter_settings_form'),
'access arguments' => array('administer site configuration'),
'type' => MENU_DEFAULT_LOCAL_TASK,
'file' => 'jcformatter.admin.inc',
);
return $items;
}
/**
* Implements hook_field_formatter_settings_form().
*/
function jcformatter_field_formatter_settings_form($field, $instance, $view_mode, $form, &$form_state) {
$display = $instance['display'][$view_mode];
$settings = $display['settings'];
$element = array();
foreach (image_styles() as $id => $style) {
$options[$id] = $id;
}
$element['pic_size'] = array(
'#type' => 'select',
'#title' => t('Button Size'),
'#description' => t('Select the image size'),
'#default_value' => $settings['pic_size'],
'#options' => $options,
);
return $element;
}
/**
* Implements hook_field_formatter_settings_summary().
*/
function jcformatter_field_formatter_settings_summary($field, $instance, $view_mode) {
$display = $instance['display'][$view_mode];
$settings = $display['settings'];
$summary = t('Using "@size" for the gallery main image', array(
'@size' => $settings['pic_size'],
)); // we use t() for translation and placeholders to guard against attacks
return $summary;
}
/**
* Implements hook_field_formatter_view().
*/
function jcformatter_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
// if there are no images, dont do anything else
if(empty($items)){
return;
}
$module_path = drupal_get_path('module', 'jcformatter');
drupal_add_js($module_path . '/scripts/jquery.jcarousel.min.js');
drupal_add_js($module_path . '/scripts/jcformatter.js');
$css_options = ".jcarousel-container{overflow: hidden;}";
drupal_add_css($css_options,'inline');
$element = array();
$settings = $display['settings'];
$data['image_style'] = $display['settings']['pic_size'];
switch ($display['type']) {
case 'jc_gallery_simple': // For this formatter
foreach ($items as $delta => $item) {
$data['images'][$delta] = array(
'alt' => $item['alt'],
'title' => $item['alt'],
'uri' => $item['uri'],
);
}
$element = array(
'#theme' => 'jc_gallery',
'#data' => $data,
);
break;
}
return $element;
}