Commit f4e52ab9 authored by jurgenhaas's avatar jurgenhaas

#2505309: Implement support for image field types

parent 9bdab677
...@@ -12,8 +12,9 @@ function colorbox_field_formatter_field_formatter_info() { ...@@ -12,8 +12,9 @@ function colorbox_field_formatter_field_formatter_info() {
return array( return array(
'colorbox_field_formatter_linked' => array( 'colorbox_field_formatter_linked' => array(
'label' => t('Colorbox link'), 'label' => t('Colorbox link'),
'field types' => array('text', 'computed', 'entityreference'), 'field types' => array('text', 'computed', 'entityreference', 'image'),
'settings' => array( 'settings' => array(
'colorbox_field_formatter_image_style' => '',
'colorbox_field_formatter_style' => 'colorbox-load', 'colorbox_field_formatter_style' => 'colorbox-load',
'colorbox_field_formatter_link_type' => 'content', 'colorbox_field_formatter_link_type' => 'content',
'colorbox_field_formatter_link' => '', 'colorbox_field_formatter_link' => '',
...@@ -71,6 +72,19 @@ function colorbox_field_formatter_field_formatter_settings_form($field, $instanc ...@@ -71,6 +72,19 @@ function colorbox_field_formatter_field_formatter_settings_form($field, $instanc
$styles = _colorbox_field_formatter_get_styles(); $styles = _colorbox_field_formatter_get_styles();
$default_style = array_pop(array_keys($styles)); $default_style = array_pop(array_keys($styles));
if ($field['type'] == 'image') {
$image_styles = image_style_options(FALSE);
$image_styles['hide'] = t('Hide (do not display image)');
$element['colorbox_field_formatter_image_style'] = array(
'#title' => t('Content image style'),
'#type' => 'select',
'#default_value' => empty($settings['colorbox_field_formatter_image_style']) ? '' : $settings['colorbox_field_formatter_image_style'],
'#empty_option' => t('None (original image)'),
'#options' => $image_styles,
'#description' => t('Image style to use in the content.'),
);
}
$element['colorbox_field_formatter_style'] = array( $element['colorbox_field_formatter_style'] = array(
'#title' => t('Style of colorbox'), '#title' => t('Style of colorbox'),
'#type' => 'select', '#type' => 'select',
...@@ -149,6 +163,22 @@ function colorbox_field_formatter_field_formatter_settings_summary($field, $inst ...@@ -149,6 +163,22 @@ function colorbox_field_formatter_field_formatter_settings_summary($field, $inst
$settings = $instance['display'][$view_mode]['settings']; $settings = $instance['display'][$view_mode]['settings'];
$summary = array(); $summary = array();
if ($field['type'] == 'image') {
$image_styles = image_style_options(FALSE);
unset($image_styles['']);
$image_style = '<strong>' . t('Content image style') . '</strong> ';
if (isset($image_styles[$settings['colorbox_field_formatter_image_style']])) {
$image_style .= $image_styles[$settings['colorbox_field_formatter_image_style']];
}
elseif ($settings['colorbox_field_formatter_image_style'] == 'hide') {
$image_style .= t('Hide');
}
else {
$image_style .= t('Original image');
}
$summary[] = $image_style;
}
$styles = _colorbox_field_formatter_get_styles(); $styles = _colorbox_field_formatter_get_styles();
$summary[] = '<strong>' . t('Style of colorbox') . '</strong> ' . $styles[$settings['colorbox_field_formatter_style']]; $summary[] = '<strong>' . t('Style of colorbox') . '</strong> ' . $styles[$settings['colorbox_field_formatter_style']];
...@@ -186,7 +216,21 @@ function colorbox_field_formatter_field_formatter_view($entity_type, $entity, $f ...@@ -186,7 +216,21 @@ function colorbox_field_formatter_field_formatter_view($entity_type, $entity, $f
foreach ($items as $delta => $item) { foreach ($items as $delta => $item) {
$uri = FALSE; $uri = FALSE;
if (isset($item['safe_value'])) { if ($field['type'] == 'image') {
$image = array(
'path' => $item['uri'],
'alt' => isset($item['alt']) ? $item['alt'] : '',
'title' => isset($item['title']) ? $item['title'] : '',
'style_name' => $settings['colorbox_field_formatter_image_style'],
);
if (empty($settings['colorbox_field_formatter_image_style'])) {
$output = theme('image', $image);
}
else {
$output = theme('image_style', $image);
}
}
else if (isset($item['safe_value'])) {
$output = $item['safe_value']; $output = $item['safe_value'];
} }
else if (isset($item['value'])) { else if (isset($item['value'])) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment