The image path is empty when an image hasn't been set for the field, but yet markup is rendered.

This is a quick and dirty patch to stop rendering of markup (both IMG and A) if the path is empty.
It is a temporary solution since it's not well thought through but please review it and consider fixing this issue with the next release.

--- imceimage/imceimage.module.old	2008-06-26 01:22:36.000000000 +0200
+++ imceimage/imceimage.module	2008-06-26 01:26:43.000000000 +0200
@@ -198,6 +198,7 @@ function imceimage_widget(&$form, &$form
  * theme an image
  */
 function theme_imceimage_image($s, $w='', $h='', $a='', $id='') {
+  if(empty($s)) return '';
   $s = 'src="'. $s .'" ';
   $a = 'alt="'. $a .'" ';
   $id = !empty($id)? 'id="'. $id .'" ':'';
@@ -212,6 +213,7 @@ function theme_imceimage_image($s, $w=''
  **/
 function theme_imceimage_formatter_link($element) {
   $item = $element['#item'];
+  if(empty($item['imceimage_path'])) return '';
   return '<a href="'. base_path() . $item['imceimage_path'] .'" class="imceimage-link">';
 }

Comments

Danial Namousi’s picture

Assigned: Danial Namousi » Unassigned
Status: Needs review » Active

Please note that you can achieve this by simply overriding the functions in your theme.

Edit: This approach stops the image from being shown when creating/editing a node, which is unsatisfactory.

panis’s picture

fixed in head. uses Danial's approach - but inserts a blank 1x1 image if there is no image..

panis’s picture

Status: Active » Fixed

fixed in head. uses Danial's approach - but inserts a blank 1x1 image if there is no image..

saborchulo’s picture

Danial is correct. My approach was overriding the default registered theme function responsible (theme name is masters), perhaps this is something that can be implemented in the default registered theme function. It's much cleaner then diving into the core code for the module, IMO.

function masters_imceimage_formatter_default($element) {
  
  if ( empty($element['#item']['imceimage_path']) ) {
  
		return '';
  }
  
  $item = $element['#item'];
  $field = $element['#field_name'];
  $delta = $element['#delta'];
  $id = "imceimage-". $field ."-". $delta;

  return theme_imceimage_image($item['imceimage_path'],$item['imceimage_width'],$item['imceimage_height'],$item['imceimage_alt'],$id);
}

Basically if no path is set when creating a content type that this field is associated with just return nothing as the output. Works perfectly.

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.

ssm2017 Binder’s picture

hello
i did like that :

function theme_imceimage_image($s, $w='', $h='', $a='', $id='') {
  $s = !empty($s)? 'src="'. $s .'" ': ' src="/sites/all/themes/mytheme/images/spacer.gif"';
	$a = 'alt="'. $a .'" ';
  $id = !empty($id)? 'id="'. $id .'" ':'';
  $w = !empty($w)? 'width="'. $w .'" ':'';
  $h = !empty($h)? 'height="'. $h .'" ':'';

  return '<img '. $s . $a . $w . $h . $id .'/>';
}
zoltán balogh’s picture

Status: Closed (fixed) » Active

Please, do not insert a blank 1x1 image if there is no image. Original Danial's solution is a good choice. If there is not an image, always return empty string.

In other case, the label of the imce image field is always displayed, and if the imce image is alone in the fieldgroup, the empty fieldgroup with only the label also displayed. This is not a good solution.

So, if there is not an image, then return empty.

yang_yi_cn’s picture

I'd like to suggest a different approach:

change the function theme_imceimage_formatter_default($element) from

/**
 * displays the image as an img
 */
function theme_imceimage_formatter_default($element) {
  $item = $element['#item'];
  $field = $element['#field_name'];
  $delta = $element['#delta'];
  $id = "imceimage-". $field ."-". $delta;

  return theme_imceimage_image($item['imceimage_path'],$item['imceimage_width'],$item['imceimage_height'],$item['imceimage_alt'],$id);
}

to

/**
 * theme the imce image, but show nothing at all if there's no image.
 */
function theme_imceimage_formatter_default($element) {
  $item = $element['#item'];
  $field = $element['#field_name'];
  $delta = $element['#delta'];
  $id = "imceimage-". $field ."-". $delta;
  if ($item['imceimage_path']) {
    return theme_imceimage_image($item['imceimage_path'],$item['imceimage_width'],$item['imceimage_height'],$item['imceimage_alt'],$id);
  }
  else {
    return '';
  }
}

As my site addes a css border to the image, when there's an empty image, it will show the bare border, which is not good. My solution doesn't show the placeholder at all thus solves the problem.

panis’s picture

Status: Active » Closed (fixed)

fixed