summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoryannickoo2012-12-29 02:54:30 (GMT)
committer yannickoo2012-12-29 02:54:30 (GMT)
commitf0fd4eba232b641568480dae6a607253c012e1f6 (patch)
treeac5cae69269d19133dda226af02c8388bde0f403
parent756c12e5c4f9f0d868464b1c3ace6762f0f4fe23 (diff)
Added possibility to select an image style and several changes.
-rw-r--r--backstretch_formatter.module43
1 files changed, 35 insertions, 8 deletions
diff --git a/backstretch_formatter.module b/backstretch_formatter.module
index fa15e8c..02e29c3 100644
--- a/backstretch_formatter.module
+++ b/backstretch_formatter.module
@@ -37,7 +37,8 @@ function backstretch_formatter_field_formatter_info() {
'label' => t('Backstretch'),
'field types' => array('image'),
'settings' => array(
- 'element' => 'body',
+ 'image_style' => '',
+ 'element' => '',
'element_other' => '',
'duration' => 5000,
'fade' => 0,
@@ -59,14 +60,23 @@ function backstretch_formatter_field_formatter_settings_form($field, $instance,
$element = array();
+ $image_styles = image_style_options(FALSE);
+ $element['image_style'] = array(
+ '#title' => t('Image style'),
+ '#type' => 'select',
+ '#default_value' => $settings['image_style'],
+ '#options' => $image_styles,
+ '#empty_option' => t('None (original image)'),
+ );
+
$element['element'] = array(
'#type' => 'select',
'#title' => t('Attach to'),
'#default_value' => $settings['element'],
'#options' => array(
- 'body' => t('Whole page'),
'other' => t('Other element'),
),
+ '#empty_option' => t('Whole page'),
'#description' => t('Where the Backstretch should be attached to.'),
);
@@ -135,17 +145,21 @@ function backstretch_formatter_field_formatter_settings_summary($field, $instanc
if (array_key_exists($name, $options_info)) {
$option = $options_info[$name];
$label = $option['label'];
- $suffix = isset($options['suffix']) ? $options['suffix'] : '';
+ $suffix = isset($option['suffix']) ? $option['suffix'] : '';
+ $type = isset($option['type']) ? $option['type'] : '';
// We need some special handling with the element setting.
if ($name == 'element') {
continue;
}
if ($name == 'element_other') {
- $value = ($settings['element'] == 'body') ? t('Whole page') : $value;
+ $value = ($settings['element'] == '') ? t('Whole page') : $value;
+ }
+ if ($name == 'image_style' && $value == '') {
+ continue;
}
// Display just the label when the setting is a boolean.
- if (!is_bool($value)) {
+ if ($type != 'bool') {
$options[$name] = $label . ': ' . $value . $suffix;
}
else {
@@ -194,13 +208,13 @@ function backstretch_formatter_field_formatter_view($entity_type, $entity, $fiel
$js = $option['js'];
// We need some special handling with the element settings.
- if ($name == 'element' || ($name == 'element_other' && $settings['element'] == 'body')) {
+ if ($name == 'element' || ($name == 'element_other' && $settings['element'] == '')) {
continue;
}
// We only put the setting into $options when it is
// not the default value.
- if ($value != $default[$name]) {
+ if ($value != $default[$name] && $js) {
$options[$js] = $value;
}
}
@@ -214,7 +228,14 @@ function backstretch_formatter_field_formatter_view($entity_type, $entity, $fiel
// Iterate all items and store the absolute url to it.
foreach ($items as &$item) {
$uri = $item['uri'];
- $options['items'][] = url(file_create_url($uri), array('absolute' => TRUE));
+ // Get url to image.
+ if ($settings['image_style']) {
+ $url = image_style_url($settings['image_style'], $uri);
+ }
+ else {
+ $url = file_create_url($uri);
+ }
+ $options['items'][] = $url;
}
// Prepare a renderable array.
@@ -264,6 +285,10 @@ function theme_backstretch($variables) {
*/
function backstretch_formatter_formatter_options() {
return array(
+ 'image_style' => array(
+ 'label' => t('Image style'),
+ 'js' => '',
+ ),
'element_other' => array(
'label' => t('Attach to'),
'js' => 'selector',
@@ -280,10 +305,12 @@ function backstretch_formatter_formatter_options() {
'center_x' => array(
'label' => t('Horizontally centerd'),
'js' => 'centeredX',
+ 'type' => 'bool',
),
'center_y' => array(
'label' => t('Vertically centered'),
'js' => 'centeredY',
+ 'type' => 'bool',
),
);
}