diff --git a/backstretch_formatter.module b/backstretch_formatter.module index fa15e8caa5efa1324ea94a782796b5d5817d7c48..02e29c3b66eb66065d5aa25da5014eae1841ae96 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', ), ); }